XML – Rules of XML serialization

  1. XML Serialization serializes the public fields and properties of a class, or the parameters and return values of methods into an XML stream.
  2. XML Serialization does not include methods, indexers, private fields, or read-only properties (except read-only collections). Because XML is an open standard, the resulting XML stream can be processed by any application on any platform. For example: ASP.NET Web Services use XML Serialization to create XML streams to pass as data throughout the Internet or Intranets. Conversely, deserialization takes such streams and constructs an object.
  3. The following items can be serialized using XmlSerialzer:
    • Public read/write properties.
    • Public fields.
    • Classes that implement ICollection or IEnumerable.
    • XmlElement objects.
    • XmlNode objects.
    • DataSet objects.
  4. XmlSerialzer gives complete control over serializing an object into XML. For example, XmlSerialzer enables you to:
    • Specify whether a field or a property should be encoded as an element or as an attribute.
    • Specify which XML namespace to use.
    • Specify the name of an element or attribute if a field / property name is inappropriate.

XML Serialization Considerations

Following should be considered when using XmlSerialzer class:

  1. Type identity and assembly information is not included. In other words, XML serialization does not maintain type fidelity. To maintain type fidelity use binary serialization instead.
  2. Only public properties and fields can be serialized. To serialize non-public data use binary serialization instead.
  3. A class must have a default constructor to be serialized with the XmlSerialzer class.
  4. Methods cannot be serialized.
  5. XmlSerialzer class can serialize classes that implement IColleciton and IEnumerable differently if they meet certain requirements.
Share this:
Share

Leave a Reply

Your email address will not be published. Required fields are marked *