File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Generate Schema for XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generate Schema for XML" Watch "Generate Schema for XML" New topic

Generate Schema for XML

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Is it possible to generate a schema for a given XML using any java API.
What about JAXP ?

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You can't generate an XSD from XML automatically - you wouldn't be able to define the ranges of values possible in an XSD, only reflect those present in the XML document. However, XSD is just XML so you certainly create one with Java.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Pete Tibbster

Joined: Aug 29, 2004
Posts: 11
There are tools out there that can create you an xsd from an example xml file. I've used Trang in the past to do this. Download trang.jar
from here

To create the xsd file open a command propt and execute the following (replacing the xml/xsd values) --->

java -jar trang.jar example.xml generated.xsd

This creates you a basic xsd based on the example xml file. It won't be able to know what the restrictions are for individual elements from your example but this is something you can add later if you know them!

hope this helps.
N Larson

Joined: Feb 16, 2005
Posts: 4
we use a tool called Torque ( You have your schema in XML and it will generate table Enums and the SQL to generate teh DB. There are also some tasks we have that compare schemas from two db to find the differences.

Check it out. Kinda confusing at first...but really nice!
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Thanks a lott for all the replies.
I just downloaded Stylus Studio, I'll chk trang & Torque today.
I agree. Here's the link:
subject: Generate Schema for XML
It's not a secret anymore!