Sign Up Now!Log In
BenD 11/16/2014 7:17:46 PM

Deserialization - turn an XML document into a .NET class

* This article, and all our great .NET Development documentation, Is available on the .NET Development menu

I get to see quite a bit of XML, and my path in the past has always been to use LINQ to iterate through the document and read it into a class. Then I’d use the class to do whatever work I need to do.

This code takes advantage of the XmlSerializer.Deserialize method. It will take the XML document an turn it into a .NET class.

To run this code, create a Windows Forms application and drop this code into the form code behind. It is complete and should run unmodified.

Note that the OrderedItem class and the getXMLDoc function both make use of namespaces for two of the elements, so we show how to code this both with and without namespace references.

Version: Unknown or N/A
Section: .NET Development