posted on Sunday, April 29, 2007 3:19 AM by Obi

How to Deserialize an XML Document into an Object

A simple yet useful way to demonstrate how to take an XML document, and deserialize it to rehydrate an object:

string xmlStuff = TaxReturnXMLDoc.OuterXml;
TextReader reader = new StreamReader(@"C:\temp\Efile-SerializedTaxReturnObject-Clean.xml");
XmlSerializer serializer = new XmlSerializer(typeof(TaxReturnEntity));
TaxReturnEntity tre = (TaxReturnEntity)serializer.Deserialize(reader);
reader.Close();

Obi

Comments