Wednesday, 12 October 2011

Controlling XML Serialization Using Attributes

The article is mainly focus on mapping the object type name with the xml file node name when De-serializing the xml file and when the node name is not a proper C# type name

Long story short, here are some brief ideas:

  • Mapping xml root element name with class name: XmlRootAttribute
  • Mapping element name other than the root with class property/field name: XmlElementAttribute
  • Mapping List of elements underneath the parent node, normally to a ArrayList (or generic List<T>): XmlArrayAttribute and XmlArrayItemAttribute
  • Mapping a xml attribute to a C# class property/field: XmlAttribute

More details you can check the Microsoft article: Controlling XML Serialization Using Attributes

No comments: