Relax NG

For my open source timetabling application (gstpl) I want to create a file format. There are some standard timetabling formats, but none of them is easy and general.

I decided to use a schema to validate the created xml file. Checking the well-formedness is easy, but for validation you need to define a grammer, i.e.define what tags (and attributes) should be possible and which combinations.

There are three main schema types: DTD, XML Schema and Relax NG (.dtd, .xsd and .rng/.rnc). The first one is not so powerful, so perhaps it is better to use XML Schema. There are a lot of editors like “NetBeans XML” which can handle the validation of XML Schema and even the schema creation from within the editor. There is a graphical editor available:

NetBeans XML DesignerNetBeans XML Editor

For Relax NG I didn’t find such a good and free editor easily for linux, although I could write alot faster with Relax NG. E.g. in XML Schema you need:

<xs:element name=”Header”>
<xs:complexType>
<xs:sequence> …

In Relax NG you only need one line:

<element name=”Header”>

And attributes are handled compareable to elements – in this way you can define e.g. that either a tag ‘test’ or an element ‘test’ should exist:

<choice>

<element name=”test”><text/></element>

<attribute name=”test”><data type=”string”/></attribute>

</choice>

I found no way to define it in XML Schema.

Now here are some editors:

  • XML Copy Editor RelaxNG editing and validation (no support for compact style)
  • Etna (only xml editor where you ensure that the created xml is valid against some given schemas)
  • nXML addon for emacs

some (extern) validators:

  • jing compact and xml style
  • rnv only compact style
  • relax ng + XML Schema via Sun Multi-Schema XML Validator (MSV), select msv.20080213.zip
  • relax ng with embedded schematron constraints via MSV, select relames.20060319.zip.

some (extern) conversation tools:

  • via MSV (select rngconv.20060319.zip) you can create a relax ng file from various schemas types.
  • trang (could even create a schema from a given example xml – I didn’t tried it)
  • relaxer is a compiler to generate various artifacts from a schema (download version 1.0), could even create a schema from a given example xml – it works!! A lot more intersting features are provided.

some tools:

  • via MSV (select xmlgen.20060319.zip) you can create xml files from various schemas types. To have some test instances of the created schema.
  • XML Schema Datatypes implementation via MSV (select xsdlib.20060319.zip) to use XML Schema Part 2

So after creating my schema in relax ng (this was really faster then with XML Schema) I can convert it into XML Schema. Then NetBeans offers a JAXB Binding (schema to java code) for XML Schemas:

NetBeans JAXB Binding Dialog

(You have to install the whole netbeans – I think the xml + soa stuff??)