Creating XSD of a XML Using Visual Studio

Introduction

I would like to share a simple way to create a XSD of a sample XML file. XSD is a schema document that is used to validate a XML file.

It validates the following things:

  1. Data type of tags (value of tags)
  2. Sequence of tags
  3. Parent-child relationship between tags and so on.

Sample XML file

<?xml version="1.0"?>
<ORDERDETAILS>
 <ORDER>
    <ORDERID>1234</ORDERID>
    <PRODUCTID>0090</PRODUCTID>
    <ORDERDATE>23-07-2013</ORDERDATE>
    <CUSTOMERID>
      x4564<CUSTOMERID>
</ORDER>
 <ORDER>
    <ORDERID>1235</ORDERID>
    <PRODUCTID>0030</PRODUCTID>
    <ORDERDATE>23-07-2013</ORDERDATE>
    <CUSTOMERID>
      x4334<CUSTOMERID>
</ORDER>
</ORDERDETAILS>


Steps

1. Open Visual Studio and create a XML file as in the following:

XSD of a XML

2. Go to the XML menu and click on the "Create Schema" command.

XSD of a XML1

3. After clicking on the "Create Schema" command we will have a XSD of the sample XML file.

XSD of a XML2

4. We can change the data type of the tags as in the following screen.



5. I changed the data type of the PRODCUTID tag to integer. And saved it as in the following:

XSD of a XML4

6. Now I changed the value of the PRODUCT ID tag to a string value. It starts validating to create the XSD file.

Now as we changed the value of the product id, it starts showing an error as in the following screen.

XSD of a XML5

Conclusion

Creating a XSD of a XML file is very simple if we use the procedure provided in this article.

Up Next
    Ebook Download
    View all
    Learn
    View all