I want to know ( java program etc ) to generate XML instance from XSD. How tools ( XML Spy, Oxygen ) generate sample XML file from XSD. What APIs can be used for generating XML from XSD and what APIs are used for checking If XML instance conforms to a XSD? Is it big deal to implement it?
Thanks in advance
Joined: Mar 22, 2006
To validate xml against XSD , I found I can use the existing parsers( using JAXP which has SAX and DOM APIs ) in current JDKs and validate. I still did not find the best way to generate xml from XSD and how tools like xml spy and oxygen generates sample xml file from xsd.
There is no such thing as the best. Sometimes, people would even be happy to just get by and obtain what they want.
Since you ask in a java-centric forum, the technique more ready to integrate into java code may be using jaxb based on  compiling the schema to java object graph (but with pre-requisite of having a w3c schema which is a reasonable assumption as you can do a free imagination of your desired xml but that is not very productive, what people really need is xml's conforms to certain blue-print which is exactly what the schema is for); then  populate the plain-old java objects with fictiitive/random data again conforming to the blue print; then  from the plain-old java objects, do some serialization to produce the xml exemplaries.
There exists specializing framework to help the random data population part () because that part would also help you to get very big xml exemplary, but the rest you still need to apply skills in xml within the range of tools bundled with jdk. Those are not readily answerable in a post or two! The way described is what you can make progress in that direction. Maybe you can now get a couple of keywords to do a better googling.
Joined: Mar 22, 2006
Thanks for your reply,
I did Hello world example for JAXB. In a scenario where I get different XSD each time to generate sample XML files , its possible to bind the schema and generate classes...but to create the content tree by using set methods is not feasible because each time its different set of set methods.I did not understand your second paragraph ( There exists specializing framework to help the random data population part () because that part would also help you to get very big xml exemplary, but the rest you still need to apply skills in xml within the range of tools bundled with jdk ) ..Can you/someone please explain in detail and set me in correct direction.
Joined: Jan 18, 2011
Can you/someone please explain in detail and set me in correct direction.