Click here to Skip to main content
Click here to Skip to main content
Alternative Article

Generate Sample XML from XSD

, 8 Jun 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This is an alternative for "Generate Sample XML from XSD".


I spent considerable amount of time to know how to generate XML from a given XSD and I had great difficulties finding solution. That is why I am sharing this Tip which is I think useful.


We have XSD.EXE available to generate XML Schema (XSD) from a XML file but sometime we might need to work generate an XML for given XSD, specially in case of writing Service Client, where for Server has exposed Request XSD and Response XSD and want to start with client Request.

Generate Sample XML using Visual Studio 

Create an XSD File

Open/Create XSD file in Visual Studio

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace=""
  <xs:simpleType name="AuthorInfor">
      <xs:documentation>this element will all authors for book</xs:documentation>
    <xs:restriction base='xs:string'>
      <xs:maxLength value='15'/>
  <xs:simpleType name="IsdnInfo">
      <xs:documentation>this element defines 10 digit ISDN code</xs:documentation>
    <xs:restriction base='xs:string'>
      <xs:maxLength value='10'/>
  <xs:complexType name="BookShelfInfo">
      <xs:choice minOccurs="1" maxOccurs="1">
        <xs:choice minOccurs="1" maxOccurs="5">
          <xs:element name="byAuthor" type="AuthorInfor"/>
        <xs:element name="byISDNNo" type="IsdnInfo"/>
  <xs:element name="MyBookShelf" type="BookShelfInfo"/>

Open XML Schema Explorer

Open XML Schema Explorer by clicking on "XML Schema Explorer" or 'Use the XML Schema Explorer...'.

You can also open "Schema Explorer" by clicking View menu.

Generate XML File

If your Schema file is valid and you are having elements, then Right click on element and click on "Generate Sample XML", this functionality generates XML file in temp folder and open ups into Visual Studio.

Generate Sample XML file generating XML like below:

<?xml version="1.0" encoding="utf-8"?>
<MyBookShelf xmlns="">
  <byAuthor>Chetan Bhagat</byAuthor>
  <byAuthor>Aditya Ghosh</byAuthor>
  <byAuthor>Reena Mehta</byAuthor>


Remember, this is quite easy to generate any sample XML file from XSD. Just think of it! 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Joshi, Rushikesh
Technical Lead Synechron
United States United States
Having 12 Years of Software Development experience.

Comments and Discussions

GeneralMy vote of 5 Pinmemberpmunari11-Dec-14 5:32 
GeneralRe: My vote of 5 PinmemberJoshi, Rushikesh12-Jan-15 6:01 
QuestionGood post PinmemberVikas Tripathi 201224-Mar-14 20:35 
GeneralMy vote of 5 Pinmembersam viper28-Aug-13 12:38 
GeneralMy vote of 5 PinmemberChargerIIC10-Jul-13 6:58 
Basic, straightforward and useful. Works in VS2012 as well.
GeneralRe: My vote of 5 PinmemberJoshi, Rushikesh10-Jul-13 6:59 
QuestionFull XML Pinmemberrezaru200023-Apr-13 18:18 
AnswerRe: Full XML PinmemberJoshi, Rushikesh18-Jun-13 9:36 
AnswerThanks for sharing Pinmembershaolinshaojie24-Sep-12 18:41 
GeneralRe: Thanks for sharing PinmemberJoshi, Rushikesh25-Sep-12 10:03 
QuestionMy vote of 5. Pinmemberqian4040112-Jun-12 23:48 
AnswerRe: My vote of 5. PinmemberJoshi, Rushikesh13-Jun-12 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 8 Jun 2012
Article Copyright 2012 by Joshi, Rushikesh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid