Serialization XML Style
XML serialization enables us to transform an instance of some class to XML and vice versa. Developers often need to perform XML serialization.
Using Basic XML Serialization
Listing 8.12 presents an example of XML serialization. In this example, there is a simple class that needs to be serialized: CellPhone. The first step is to create an instance of the class XmlSerializer and initialize is with the type XMLSerializationSample.CellPhone. Next, the CellPhone class is instantiated and the properties set to the desired values. Finally, the Serialize method is invoked and the CellPhone is serialized.
Listing 8.12. XML Serialization Example
using System; using System.Xml.Serialization; namespace XMLSerializationSample { public ... |
Get Microsoft® Visual C#® .NET 2003 Unleashed 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.