I have a class object for XML serialization
[XmlType("PAYMENT")]
public class PaymentXML
{
    [XmlElement(ElementName = "REQUEST")]
    public RequestXML Request { get; set; }
    [XmlElement(ElementName = "META")]
    public MetaXML Request { get; set; }
    //Property that I dont want to be serialized
    public Subscriber Subscriber { get; set; }
}
the serialization
var xml = new PaymentXML();
string path = HttpContext.Current.Server.MapPath(@_xmlResponseDir + _responsePath);
using (var sw = new StreamWriter(path))
{
    var ns = new XmlSerializerNamespaces();
    ns.Add("", "");
    var serializer = new XmlSerializer(typeof(PaymentXML), new XmlRootAttribute("XML"));
    serializer.Serialize(sw, xml, ns);
}
The problem is, it's also serializing the Subscriber property. I only want the RequestXML and MetaXML to be serialized into XML. How can I exclude the Subscriber property in the serialization process?
Use the [XmlIgnore] attribute:
// Property that I don't want to be serialized.
[XmlIgnore]
public Subscriber Subscriber { get; set; }
                        Add the XmlIgnore attribute to that property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With