Article ID: 314150
This article was previously published under Q314150
This article provides a roadmap to learn and to master serialization and deserialization of XML with the .NET Framework (System.Xml namespace).
Roadmap articles provide links to useful information, including online documentation, Microsoft Knowledge Base articles, and Microsoft white papers, to help you learn about a Microsoft product or technology. Microsoft Knowledge Base How To articles and walkthroughs provide step-by-step instructions to complete specific tasks. QuickStart sample files are ready-made programs that illustrate a technique.
The .NET Framework features two serializing technologies:
The following links provide overview information about XML serialization and deserialization in Microsoft Visual Studio .NET:
Introducing XML Serialization
XML and SOAP Serialization
The central class in the namespace is the XmlSerializer class. To use this class, use the constructor of the XmlSerializer to create an instance of the class by using the Type of the object to serialize. After an XmlSerializer is created, create an instance of the object to serialize. You must also create an object to write the file to a document or stream, such as a Stream, a TextWriter, or an XmlWriter. You can then call the Serialize method to convert the object to an XML document.
To deserialize an object from an XML document, create a suitable object to read the document or stream (again a Stream, a TextWriter, or an XmlWriter). Invoke the Deserialize method while casting the resulting object to the Type of the original object that was serialized.
To control the serialization more, the System.Xml.Serialization namespace provides several Attribute classes that can be applied to members of a class. For example, if a class contains a member that will be serialized as an XML element, you can apply the XmlElementAttribute attribute to the member. When applying the attribute, you can specify details such as the actual XML element name by using the ElementName property.
The following link provides architectural (internal) information about XML serialization and deserialization:
XML Serialization Class
XML Serialization with XML Web ServicesThe "Examples of XML Serialization" link gives several code samples that demonstrate XML serialization, including the following:
Overriding XML Serialization
.NET Samples - How To: XML Serialization
Examples of XML SerializationThe "Controlling XML Serialization Using Attributes" link discusses the following topics with code samples:
Controlling XML Serialization Using Attributes
(http://support.microsoft.com/kb/315703/EN-US/ )HOW TO: Serialize an Object to XML by Using Visual Basic .NET
316730You can also run XSL transformations (XSLT), query and modify XML data by using DOM, and serialize or deserialize XML data by using the System.Xml classes in the .NET Framework. For more information, see the following Knowledge Base article:
(http://support.microsoft.com/kb/316730/EN-US/ )HOW TO: Serialize and Deserialize XML in Visual Basic .NET
(http://support.microsoft.com/kb/313651/EN-US/ )Roadmap for XML in the .NET Framework
Using Schema and Serialization to Leverage Business Logic
http://support.microsoft.comYou have several options to find answers to your questions. You can search the Microsoft Knowledge Base, post your questions or share your experiences on Microsoft newsgroups, obtain the latest service packs and news about a specific product, or contact Microsoft Product Support.
Article ID: 314150 - Last Review: December 12, 2012 - Revision: 4.0