Chapter 18. The System.Xml.Serialization Namespace

The System.Xml.Serialization namespace contains classes that are used to control the serialization of .NET types to XML. Serialization refers to the process of encoding an object as a series of bytes, which can then be decoded by another program in order to replicate the original object. The System.Xml.Serialization namespace supports XML serialization, the serialization of objects to arbitrary XML formats, including SOAP. For serialization to binary and user-defined formats, as well as to specific SOAP formats used for the transmission of objects between instances of .NET applications, collectively known as runtime serialization, see the System.Runtime.Serialization namespace.

SOAP, which formerly stood for Simple Object Access Protocol, defines a standard mechanism for encoding objects as XML. The specification for SOAP 1.1 is available at http://www.w3.org/TR/SOAP. For more information about SOAP, see Programming Web Services with SOAP, by Doug Tidwell, James Snell, and Pavel Kulchenko (O’Reilly). SOAP Version 1.2 recently became a W3C Recommendation.

To serialize an object instance to XML, create an instance of XmlSerializer for that type by passing the type as a parameter to XmlSerializer’s constructor. Then use the XmlSerializer.Serialize( ) method to serialize the object to a System.IO.Stream, System.IO.TextWriter, or System.Xml.XmlWriter. To deserialize an object from XML, use the staticXmlSerializer.Deserialize( ...

Get .NET & XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.