• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generating XML instance from XSD

 
sandeep nanjegowda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks g tsuji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic