Article ID: 815813 - Last Review: September 22, 2011 - Revision: 6.0 How to serialize an object to XML by using Visual C#
On This PageSUMMARYThis step-by-step article describes how to serialize an
object to XML by using Visual C#. This method is useful for persisting the
state of an object. This method is also useful for cloning an object by
de-serializing the XML back to a new object. RequirementsThe following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
XML SerializationSerialization is the process of taking the state of an object and persisting it in some fashion. The Microsoft .NET Framework includes powerful objects that can serialize any object to XML. The System.Xml.Serialization namespace provides this capability.Follow these steps to create a console application that creates an object, and then serializes its state to XML:
Complete Code ListingVerificationTo verify that your project works, press CTRL+F5 to run the project. A clsPerson object is created and populated with the values that you entered. This state is serialized to XML. The console window shows the following:TroubleshootThe Xml.Serialization.XmlSerializer object performs only shallow serialization. If you also want to serialize the private variables of an object or child objects, you must use deep serialization.REFERENCES For more information, visit the following Microsoft
Developer Network (MSDN) Web site: Introducing XML Serialization http://msdn.microsoft.com/en-us/library/182eeyhh(VS.80).aspx (http://msdn.microsoft.com/en-us/library/182eeyhh(VS.80).aspx) | Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|





















Back to the top