Relax NG

Posted on Wednesday, August 13, 2008 11:18 AM

Relax NG (relaxing)

Why?

The following quote from the paper XML Fever by Erik Wilde and Robert J .Glushko gives a good explanation:

XSDL's complexity allows a given logical model to be encoded in a plethora of ways (this fever will mutate into an even more serious threat with the upcoming XSDL 1.1, which adds new features that overlap with existing features). A cure for schema option paralysis is to use alternative schema languages with a better separation of concerns (such as limiting itself to grammars and leaving data types and path-based constraints to other languages), most notably RELAX NG.

How?

When writing a schema I prefer the compact syntax, emacs rnc-mode being a helpful aid.

Another very useful feature is the instant validation provided by emacs nxml-mode when opening an XML file and while editing it. All you need to do is feed it the rnc schema file.

Other validation tools I use:
For Java: Jing or MSV
For .Net : Tenuto

Beware of a bug in Jing when using javax.xml.validation as in the code example below:

import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import java.io.File;

public class RELAXNGValidation {
    public static void main(String[] args) throws Exception {

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
        Schema schema = sf.newSchema(new File(args[0]));
        schema.newValidator().validate(new StreamSource(args[1]));
    }
}

A useful XML schema conversion tool is Trang.

Update: 29 Oktober 2008

James Clark is working on Jing again. Jing and Trang are now hosted on Google Code

Post Comment

Title  
Name  
Url
Comment   

ATTENTION: the code you need to copy is CaSe SeNsItIvE and is required to prevent spam.
Enter the code you see: