Select the product you need help with
How to serialize an object to XML by using Visual Basic .NET or Visual Basic 2005Article ID: 315703 - View products that this article applies to. This article was previously published under Q315703 On This PageSUMMARY This step-by-step article describes how to serialize an
object to XML by using Visual Basic .NET or Visual Basic 2005. This method is useful for persisting
an object's state. 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:<?xml version="1.0" encoding="IBM437"?> <clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <FirstName>Jeff</FirstName> <MI>A</MI> <LastName>Price</LastName> </clsPerson> TroubleshootingThe Xml.Serialization.XmlSerializer object performs only shallow serialization. If you also want to serialize an object's private variables or child objects, you must use deep serialization.REFERENCES For more information, visit the following MSDN Web site: Introducing XML Serialization
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconintroducingxmlserialization.asp)
Properties | Article Translations |


Back to the top








