HowTo: Create a Data class from an XML document
This article explains how to create a data class from an xml document.
In our Windows Phone application, we need to parse the XML data and fill (serialize) them to a class. This class will be used to populate the UI and works as our data(model) class.
We can generate our data classes easily using Visual Studio's XSD tool, by following below steps:
- Register Microsoft SDK's binary folder (below) path to "Path" in environment variable. (If not done already)
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin
- Create an XML file from your response string.
- Consider the below XML for our example.
- Open the command prompt and traverse up to directory where you saved above XML file.
- On command prompt run the below command
- (Assuming that xml file in step 3 has name Students.xml")
- If we have properly set the environment the above command will be executed with success.
- The above command will generate the Students.xsd file in same folder where our xml file resides. This xsd is the XML schema file and will be used in our next step to generate our C# class file.
- Now, on command prompt run the following command to generate the "Students.cs" file in same folder where our above two files reside.
This is the our data class which we need to import in our project to de-serialize the students XML response.
Check this article where I explain how to de-serialize the XML response in data class's object.