Is it possible to exclude some type elements from serialization of XmlSerializer?

I have some public elements that I do not want to serialize, I was wondering if there is an attribute for this?

+5
source share
5 answers

Are you looking for XmlIgnore

+7
source

Use XmlIgnoreAttribute to do it statically, as others have advised.

You can also do this dynamically. Suppose you have a serializable Name property . Then the following:

[XmlIgnore]
public bool NameSpecified {
    get {
        // your logic here
    }
}

getter true, XML-, . NameSpecified [XmlIgnore], .

+5

XmlIgnore will do the trick.

+4
source

Use XmlIgnore attribute

+2
source

Following Azheglov’s comment regarding the “Specified” suffix, the attribute is DefaultValuealso taken into account during serialization, and the value will not be serialized at all if it is by default.

0
source

All Articles