Create an XSD from XML using Trang

I recently needed to create an XML Schema XSD file from an existing XML file. A short research pointed me to Trang. Description from their website:

Trang, a program for converting between different schema languages, focused on RELAX NG; in particular, it can convert between the compact and XML syntaxes, it can convert between RELAX NG and DTDs, and it can convert from RELAX NG to W3C XML Schema

But beside the convertion between different schema languages, Trang is also able to create schemas based on XML files.

The creation of an XSD is done as follows for UTF-8 encoding using a JRE 1.5 or above:

 
java -jar trang.jar -i encoding=UTF-8 message.xml message.xsd

Or, with explicit input and output format if the former command does not work as expected:

java -jar trang.jar -I xml -O xsd -i encoding=UTF-8 message.xml message.xsd

Easy.

Original post: http://peter-on-java.blogspot.com/2012/10/create-xsd-from-xml-using-trang.html

Tags xml