While we are working with Alfresco WCM, in some cases we need to create an XSD for each content type and it's a time consuming job even though the structure of the content type is not complicated. But in the case of creating an XSD from existing sample XML document then you don't need to do the tedious job and can save lots of times by using conversion tools such as InstanceToSchema or Sun RELAX NG Converter. But I personally like "trang" which is light and powerful.
What is trang?
Trang is a Java-based tool which translates between different forms of xml definitions such as Regular Language Description for XML Next Generation(RELAX NG) XML Syntax, RELAX NG compact syntax, XML 1.0 Document Type Definition(DTD) and W3C XML Schema(XSD). Trang can also infer a schema from one or more example XML documents.
1. Prerequisite : The file trang.jar contains Trang packaged for use with a Java runtime and it requires a Java runtime compatible with the Java 2 Platform, J2SE version 5 or any later version.
2. Download trang.jar Once you have installed a Java runtime, then download the latest trang.jar from here
3. Running It's simple. The command is : java -jar trang.jar args where args are additional command-line arguments described here. And in our case (create an XSD from XML), the command will be
java -jar trang.jar
So, let's create an XSD from sampel XML document
3.1 Assume the "trang.jar" is in "/home/user/trang" and the sample XML file named "test.xml" are in the same folder.
3.2 Run the command below :
java -jar trang.jar text.xml test.xsd
And you will see the test.xsd file in the "trang" folder.