aspose file tools*
The moose likes XML and Related Technologies and the fly likes Generating XML instance from XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Generating XML instance from XSD " Watch "Generating XML instance from XSD " New topic
Author

Generating XML instance from XSD

sandeep nanjegowda
Greenhorn

Joined: Mar 22, 2006
Posts: 7
Hi,

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

Sandeep
sandeep nanjegowda
Greenhorn

Joined: Mar 22, 2006
Posts: 7
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.

Thanks
Sandeep
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
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 [1] 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 [2] populate the plain-old java objects with fictiitive/random data again conforming to the blue print; then [3] 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 ([2]) 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.
sandeep nanjegowda
Greenhorn

Joined: Mar 22, 2006
Posts: 7
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 ([2]) 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.

Thanks
Sandeep
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
Can you/someone please explain in detail and set me in correct direction.

Detail? no, only in kind. In the specific facility mentioned in [2], I can suggest you read and try the framework podam.
http://home.btconnect.com/jemosAgile//projects/podam/index.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42930
    
  68
In general, there is an infinite number of XML documents that conform to a specific given XSD, so on that basis alone this is not possible.

Why, exactly, do you want to do this?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
In general, there is an infinite number of XML documents that conform to a specific given XSD, so on that basis alone this is not possible.

That is some logical deduction that I don't follow.
sandeep nanjegowda
Greenhorn

Joined: Mar 22, 2006
Posts: 7
Thanks g tsuji
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generating XML instance from XSD