How to map XML file content to C# object(s) How to map XML file content to C# object(s) xml xml

How to map XML file content to C# object(s)


It sounds like you want use XML serialization. There is a lot already out there, but this is a pretty simple example.http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization

The snippet you want is about 1/4 of the way down:

XmlSerializer deserializer = new XmlSerializer(typeof(List<Movie>));TextReader textReader = new StreamReader(@"C:\movie.xml");List<Movie> movies; movies = (List<Movie>)deserializer.Deserialize(textReader);textReader.Close();

Hopefully, this helps


You can use the XmlSerializer class to serialize CLR Objects into XML. Here is the MSDN documentation with some sample code : http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx