O'Reilly logo

.NET & XML by Niel M. Bornstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required