Generating XMLfrom XSD at runtime [message #563376] |
Mon, 13 August 2012 06:25 |
|
tigsav
Messages: 49 Registered: April 2012
|
Member |
|
|
Hello All,
I Have got a requirement where we have to generate an xml conforming to a particular XSD.
What i will be having already in place is an XSD document.
We are thinking of making a procedure which will be recieving the set of inputs required for creating that xml.(Data content of that XML.)We would have to make the XML according to that XSD.
Everytime Parsing the XSD is not feasible.
We are looking at a solution which would be easy to make the xml from xsd at runtime.
These values (DATA) will be available at run time.
Thanks in Advance!!!!
|
|
|
|
|
|
Re: Generating XMLfrom XSD at runtime [message #566767 is a reply to message #563376] |
Wed, 19 September 2012 07:18 |
|
tigsav
Messages: 49 Registered: April 2012
|
Member |
|
|
hi,
Consider an example :
Suppose the XSD is :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="[url]http://www.w3.org/2001/XMLSchema[/url]">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
The values for name ,address,and all elements will be known at run time .Now we need to have a code which will generate an xml based on that values.
I know only the structure of xsd.
Also the code needs to be generic handling all possible types of XSD's i.e If any future any new XSD comes then my code should not change.
[mod-edit: code tags added by bb; next time please add them yourself]
[Updated on: Wed, 19 September 2012 12:26] by Moderator Report message to a moderator
|
|
|
|
Re: Generating XMLfrom XSD at runtime [message #566824 is a reply to message #563376] |
Thu, 20 September 2012 00:07 |
|
tigsav
Messages: 49 Registered: April 2012
|
Member |
|
|
Sorry for not providing that earlier,
<?xml version="1.0" encoding="ISO-8859-1"?>
<shiporder orderid="889923"
xmlns:xsi="[url]http://www.w3.org/2001/XMLSchema-instance[/url]"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
[mod-edit: code tags added by bb again]
[Updated on: Thu, 20 September 2012 11:16] by Moderator Report message to a moderator
|
|
|
|