Wednesday, March 9, 2011

Inferring an XSD from XML

When working with forms in LiveCycle, it is important to know the structure of the XML data that gets exported from the form and passed around the LiveCycle process. In ES2 Adobe has introduced the ability to create and use an Adobe Data Model to describe the structure. Workbench has a tool which will allow you to to create these models and Adobe is really trying to encourage developers to use it more, not just in LiveCycle development, but also in enterprise level development with Flex and Java.
However, being old school, I still found it more comfortable to use an XML schema file (.xsd) to describe the structure of the data in the form and to use in a LiveCycle process to be able to access the separate fields in a form.
Creating an XSD can be troublesome, creating it from scratch even more so. The easiest method to create the XSD file is by inferring it from an XML file. There are many XML editors that are able to do this, a few being:
Unfortunately you have to pay for these software. There are a few free options out there, my favorite being Trang. Its a small and simple command line tool that works in multiple platforms. The way to use it is to
  1. Download Trang. You can download Trang at http://www.thaiopensource.com/relaxng/trang.html
  2. Extract the files from the zipped download
  3. Run the command passing your input XML file (it can be multiple XML files) and specifying the result XSD file.
The syntax of the command should look like;
java -jar trang.jar input.xml input2.xml input3.xml output.xsd
And its as simple as that! You have your XSD file that you can use in your form and in your process to describe the structure of the data.

No comments: