-1

I have a complex XML file which has several sub entities inside a main entity now i want to deserialize and map them to objects of the relevant classes

I'm using C# how do i do this?

Guruparan
  • 71
  • 1
  • 8
  • Possible duplicate of http://stackoverflow.com/questions/226599/deserializing-xml-to-objects-in-c-sharp – Bob2Chiv Mar 27 '12 at 17:04
  • 1
    Here's a tutorial using the [XmlSerializer](http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx): http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization Although the tutorial doesn't explicitly dive into sub entities, as long as the classes that your properties use are serializable, it will cascade through automatically. – Chris Sinclair Mar 27 '12 at 16:50
  • Here's a link that explains how to do it. http://www.codingday.com/xml-c-class-generator-for-c-using-xsd-for-deserialization/ Basically you need to create a XSD file from your xml to serialize the xml to a class. – lurkerbelow Mar 27 '12 at 16:52

1 Answers1

1

You can use XSD.exe to generate a class for you

http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=VS.100).aspx

You can just pass it an XML file and it will generate the schema and create a class.cs which can be added to your project

This will be different depending on OS and version, but the exe is located at this location on my pc: C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\

msmucker0527
  • 5,164
  • 2
  • 22
  • 36