anvarik
anvarik

Reputation: 6487

Generate XSD files in Java

Is there any way (not from classes/JAXB) to create XSD schemas in Java? I can parse it with the help of some libraries ie XSOM, Jdom etc. But could not find anything to create.

Upvotes: 4

Views: 3527

Answers (4)

Nick Wilson
Nick Wilson

Reputation: 4989

You could use the Eclipse XSD project, part of the Eclipse Model Development Tools. It provides a data model and API for programatically creating schemas.

Upvotes: 1

Moataz Elmasry
Moataz Elmasry

Reputation: 2519

Take a look at apache xerces http://xerces.apache.org/xerces2-j/xml-schema.html

still there's no out of the box solution to handle xsd files

Upvotes: 1

GingerHead
GingerHead

Reputation: 8230

To create XSD is to use java classes/coding (is inevitable):

Just use Java DOM and create a document then the main node and create other nodes to attach to it and voila!

Upvotes: 0

Alpedar
Alpedar

Reputation: 1344

I don't know about any easy to use way. I considered using dom4j (because I use it for other purposes, but any other generic xml manipulation library is equivalent) and manualy create it (1).

But then I realized I can use JAXB to generate object model of xml schema, populate it with what i wanted (turned out to be much less comfortable than I hoped for) and marshall it(2). Its via JAXB, but without creating classes for your schema, so maybe it can be usefull to you.

via 2 is hard (but not impossible) to create invalid schema, but its sometimes hard to find out how to create schema I wanted. So I ended creating it in editor, then unmarshalling it and exploring its object representation. In the end, creating it via 1) and then validating it (which I had to do anyway) would be less chore.

Upvotes: 1

Related Questions