What's the best tool out there to create (or to infer) an XSD schema from XML document? I need it to be linux-compatible.
Asked
Active
Viewed 1.4k times
14
-
Hmm, how would that work? XSD is extremely semantic, and that's something you can't infer from examples. – Šimon Tóth Jul 27 '11 at 11:20
-
I have a simply XML response, and I want to create, based on this XML, a XSD schema. I've found some tools online, like http://www.flame-ware.com/products/xml-2-xsd/ , but I'd like to know if there's something better... – Aitor Jul 27 '11 at 11:25
-
On windows this is easy as there is a tool in the .net SDK, sorry don't know about unix – Ian Ringrose Jul 27 '11 at 12:15
-
1@Let_M_Be, in a lot of cases a tool can create a good enough XSD for a example XML document. A set of classes for read/writing the xml can them be auto created from the XSD (maybe with a bit of hand editing of the XSD if needed) – Ian Ringrose Jul 27 '11 at 12:16
-
@Let_M_Be: When creating XSD's, It's a huge time saver. First I get some XML examples, and *convert* to respective XSD's. Then I combine the appropriate parts together, and make some hand edits, to make the final XSD. It's never 100%, as it only covers the your original XML input, but that does not make the process worthless. – J. M. Becker Dec 16 '12 at 17:38
2 Answers
20
In the past I have used Trang : http://www.thaiopensource.com/relaxng/trang.html
Its old and basic but i find it generates cleaner schemas than other tools (e.g. XMLSpy)

Sam
- 6,240
- 4
- 42
- 53
-
Finally, trang is the tool we're using to transform a XSD in a DTD, and also the reverse. Thanks! – Aitor Dec 17 '12 at 11:33
-
10
-
This seems to work well. Usage: trang -I xml -O xsd example.xml schema.xsd – Aaron Swan Feb 03 '20 at 20:12
3
You can create a DTD from XML using DTDGenerator from the saxon project. Then you can convert this to a XSD using W3C's dtd2xsd.pl. See Free DTD to XSD conversion utility?.
-
Thank you.. Perhaps it's a better method convert to DTD and then to XSD than directly to a XSD. – Aitor Jul 27 '11 at 12:10
-
Wouldn't XML->XSD generally be better than XML->DTD->XSD since XSD is potentially more descriptive? The latter could lead to a less specific XSD. – David Moreau Jul 19 '21 at 14:34