Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD generator from several XMLs

Tags:

xml

xsd

I know it is possible to generate skeleton XSD from XML. For example this post has good answers.

The question is how to generate XSD based on several XMLs. The idea is that each XML might have several different occurences of optional, arrays, choice and the like. From all those examples, I would like to compose the most accurate XSD.

I know there might be collisions and the like but assuming all the XML came from an uknown XSD, it should be theoreticaly possible. But is there such tool?

Thanks

like image 796
Ragoler Avatar asked Jun 30 '09 19:06

Ragoler


People also ask

How do I create an XSD from an XML 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.

Can we generate XML from XSD?

We can use Eclipse IDE to easily generate XML from the XSD file. Just follow the below steps to get XML from XSD. Select XSD File in project, right click for Menu and select Generate > XML File… Provide the XML file Name and XML File location in the popup window.

Can we generate XSD from JSON?

A possible roundabout way of getting your XSD is to start with a json doc (not the jsonschema) that's pretty complete and conformant to your jsonschema, use any of a multitude of json to xml converters, and convert your xml to xsd (one such tool here).


1 Answers

Trang is just such a tool written in by the notable James Clark. It can translate between different forms of xml definitions such as Relax NG normal and compact syntax, old school DTD and XML schema. It can also infer schema from one or more xml files.

NOTE: The project has moved to Github. http://github.com/relaxng/jing-trang is the new location of the Trang repo

If you run ubuntu trang is packaged in the universe repository but that version seems a bit broken and a clean download from the link above is probably your best option. Assuming trang.jar is in the current directory:

java -jar trang.jar -I xml -O xsd file1.xml file2.xml definition.xsd

should do what you want.

like image 167
Knut Haugen Avatar answered Oct 13 '22 07:10

Knut Haugen