Namespaces
Variants
Actions

HowTo: Create a Data class from an XML document

Jump to: navigation, search
SignpostIcon XML 40.png
Article Metadata

Tested with
SDK: Windows Phone 7.1

Compatibility
Platform(s): Windows Mango

Article
Created: Kavit Patel (26 Mar 2012)
Last edited: hamishwillee (30 Nov 2012)

Introduction

This article explains how to create a data class from an xml document.

Implementation

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:

  1. 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
  2. Create an XML file from your response string.
  3. Consider the below XML for our example.
    XMLResponse.png
  4. Open the command prompt and traverse up to directory where you saved above XML file.
  5. On command prompt run the below command
    xsd Students.xml
    (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.
  6. 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.
  7. Now, on command prompt run the following command to generate the "Students.cs" file in same folder where our above two files reside.
    xsd/c Students.xsd
    XSDExample.jpg

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.

This page was last modified on 30 November 2012, at 08:29.
184 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved