Monday, April 5, 2010

XML serialization

XML is a softare industry standard, serializing with XML gives to your applications great interopeability.
However, XML serialization doesn't serialize your private members, neither object graphs, only single objects.
The process for XML serialization is very similar to binary or SOAP serialization: you must create a stream, TextWriter or XmlWriter in wich the XmlSerializer class can store the XML output through its Serialize method.  The XmlSerializer constructor requieres the type of object that you will use with the class.  For deserialization, you must use the Deserialize method of the same class.
Ir order to use XML serialization in a custom class, this class should be public and must have a paremeterless constructor.  Unlike binary or SOAP serialization, XML serialization doesn't requiere the Serializable attribute in your class.  Any private or protected member of your custom class will be skiped.
Unless you specify a diferent behavior through attirbutes, the .Net XML serialization will use the standard class or member names to identify XML elements.  Each member in your class will be a XML element.  If you have an XSD schema, you can use the xsd.exe tool, wich creates a class that respects that schema when is serialized on XML.

    No comments:

    Post a Comment

    Bookmark and Share