By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,071 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,071 IT Pros & Developers. It's quick & easy.

Create a sample XML data for XML Schema

P: n/a
Hello,
Let us say that I have a schema or complex type like this one below:

Is there a way programtically or a tool to create sample XML file/data for
the schema?. I have number of such complex tpyer/schemas for which I need to
create sample XMLs so I thought of doing it programatically.. Any pointers
would be appreciated.

Thanks.

**********************
<xs:complexType name="AddRequest">
<xs:annotation>
<xs:documentation>
Add a group.
The response is either a SuccessResponse or an ErrorResponse.
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="Request">
<xs:sequence>
<xs:element name="serviceProviderId" type="xs:string"/>
<xs:element name="groupId" type="xs:string"/>
<xs:element name="defaultDomain" type="xs:string"/>
<xs:element name="userLimit" type="xs:string"/>
<xs:element name="groupName" type="xs:string" minOccurs="0"/>
<xs:element name="callingLineIdName" type="xs:string"
minOccurs="0"/>
<xs:element name="timeZone" type="xs:string" minOccurs="0"/>
<xs:element name="locationDialingCode" type="xs:string"
minOccurs="0"/>
<xs:element name="contact" type="xs:string" minOccurs="0"/>
<xs:element name="address" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
**********************

Apr 7 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Ganesh Muthuvelu wrote:

Let us say that I have a schema or complex type like this one below:

Is there a way programtically or a tool to create sample XML file/data for
the schema?.


Both .NET and MSXML (4 and later) provide a schema object model (SOM)
which you can use to traverse XSD schemas programmatically and extract
element/attribute/type declarations. But of course getting from that to
a sample document is additional work.

MSXML SOM documentation is here:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/85b447ee-70d0-4456-9ad7-70b4e2d1f3fa.asp>

..NET 2.0 SOM introduction is here:
<http://msdn2.microsoft.com/en-us/library/ms255931.aspx>

..NET 1.x SOM introduction is here:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconxsdschemaobjectmodelsom.asp>

..NET 2.0 has an API for inferring a schema from an instance document but
there is no direct API for what you want to (the other way round).

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 7 '06 #2

P: n/a
Initially you could use a tool like Altova XML Spy (or equivalent)

It has under the DTD/Schema menu an option Generate Sample XML File...

You could use this on a schema by schema basis.

But is a bit "manual"

Perhaps you want an exe to allow you to operate on a batch of Schemas
or code from the System.XML Namespace to do a batch for you?

Apr 7 '06 #3

P: n/a
Not .NET so sort of the wrong group here but this may be of use.

http://www.sun.com/software/xml/deve...ancegenerator/

Dickster

Apr 7 '06 #4

P: n/a
The following article describes how you can use classes in the
System.XML.Schema namespace of the Microsoft .NET Framework to build a tool
that generates sample XML documents that conform to a given schema:
http://msdn.microsoft.com/library/en...tml/xmlgen.asp

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Ganesh Muthuvelu" <Ga*************@discussions.microsoft.com> wrote in
message news:C3**********************************@microsof t.com...
Hello,
Let us say that I have a schema or complex type like this one below:

Is there a way programtically or a tool to create sample XML file/data for
the schema?. I have number of such complex tpyer/schemas for which I need
to
create sample XMLs so I thought of doing it programatically.. Any pointers
would be appreciated.

Thanks.

**********************
<xs:complexType name="AddRequest">
<xs:annotation>
<xs:documentation>
Add a group.
The response is either a SuccessResponse or an ErrorResponse.
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="Request">
<xs:sequence>
<xs:element name="serviceProviderId" type="xs:string"/>
<xs:element name="groupId" type="xs:string"/>
<xs:element name="defaultDomain" type="xs:string"/>
<xs:element name="userLimit" type="xs:string"/>
<xs:element name="groupName" type="xs:string" minOccurs="0"/>
<xs:element name="callingLineIdName" type="xs:string"
minOccurs="0"/>
<xs:element name="timeZone" type="xs:string" minOccurs="0"/>
<xs:element name="locationDialingCode" type="xs:string"
minOccurs="0"/>
<xs:element name="contact" type="xs:string" minOccurs="0"/>
<xs:element name="address" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
**********************

Apr 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.