Reputation: 676
As part of our application we need to develop a module that takes in an XSD schema and gives out a sample XML. The XSD schemas will be supplied during runtime. So is there any Java API out there that can do the job?
Searched this forum and found the following similar questions. But the discussions were around tools to generate sample XML from XSD. Could not find any reference to APIs.
how-to-generate-sample-xml-documents-from-their-dtd-or-xsd
tool-to-generate-xml-file-from-xsd-for-testing
xml-instance-generation-from-xml-schema-xsd
Upvotes: 9
Views: 12949
Reputation: 121
i found java API to generate XML sample from XSD http://code.google.com/p/jlibs/wiki/XSInstance,
Upvotes: 6
Reputation: 4454
There is no such API, but it's possible.
'gives out sample XML' means that you will have to implement generation of sample XML node(s) from XSD basic types like <xs:element name="value" type="xs:integer" minOccurs="0"/>
, taking care of minoccurs/maxoccurs attributes, not storing dates in xs:integer
nodes, etc, etc..
Once it's done, the rest is not a problem: traversing XSD with XPath
or org.w3c.dom.*
, flattening complex types and extensions will do the trick. I bet you'll receive working traversing code here on stackoverflow within minutes after posting question.
Upvotes: 0