Sunday, May 3, 2009

C# - System.Xml.Serialization namespace

Let's review something about XML serialization first:
- It provides interoperability and communicability with different platform and also flexibility to conform to XML schema as a pattern.
- XML serialization can not be used to serialize private data.
- A class which wants to be serialized by XML serialization should be public and all members should be defined as public too, and you have to create a parameterless constructor for that class.
- Arrays, collections, Data sets, instances of XmlElement or XmlNote class can be serialized with XmlSerializer

XML Serialization Attributes
It's possible to use attributes to create XML documents that conform to specific standards.
Example:
- [XmlIgnore] in front of a public properties and fields will cuase to ignore it when the class is serialized, it's similar to [NonSerialized] attribute in standard serialization.
- [AmlAttribute] will cause to consider the serialized member as XML attribute.

For more details and to see the list of attributes, please look at the following URL:
XmlAttributes Members
Share/Bookmark

No comments: