Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate XSD files in Java

Tags:

java

xml

xsd

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.

like image 405
anvarik Avatar asked Jul 11 '12 13:07

anvarik


People also ask

How do I create an XSD file?

With the desired XML document opened in the active editor tab, choose Tools | XML Actions | Generate XSD Schema from XML File on the main menu. The Generate Schema From Instance Document dialog box opens. and select the desired file in the dialog that opens.

What are XSD files in Java?

xsd is the XML schema you will use as input to the JAXB binding compiler, and from which schema-derived JAXB Java classes will be generated.


2 Answers

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.

like image 190
Alpedar Avatar answered Sep 28 '22 04:09

Alpedar


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

like image 27
Moataz Elmasry Avatar answered Sep 28 '22 02:09

Moataz Elmasry