As far back as the original XML 1.0 Recommendation, XML has included the ability to validate it, or compare it to a predefined structure. The first version of validation was called the Document Type Definition (DTD), but many developers thought this was too simple: It doesn't use XML syntax, and doesn't enable developers to specify many of the rules needed in the real world. The W3C then developed XML Schema, but many developers thought this was too complicated: It uses XML syntax and enables users to create just about any rule under the sun, but at the cost of adding complexity. Others combined the TREX and RELAX proposals into RELAX NG and many developers think it's just right. It uses XML syntax, and it enables developers to create most of the same rules as the W3C XML Schema language, but with a greatly simplified syntax.
This tutorial explains the concepts behind RELAX NG in both its XML and compact forms. It covers:
- Creating a RELAX NG schema
- Optional items
- Mixed content
- Modularizing a schema
- Creating these rules using the compact syntax
The tutorial doesn't actually build an application; it uses a command-line application to simply validate the document against the schema document.
This tutorial doesn't involve any actual programming, but to verify the schema files you create, you'll need a validator. RELAX NG validators exist for a number of different languages, including:
- Java technology -- Jing (http://www.thaiopensource.com/relaxng/jing.html) and MSV (http://wwws.sun.com/software/xml/developers/multischema/)
- C -- Libxml2 (http://www.xmlsoft.org/)
- C# -- Tenuto (http://sourceforge.net/projects/relaxng)
- Python -- XVIF (http://freshmeat.net/projects/xvif/?topic_id=868)
- ActiveX -- a DLL, VBRELAXNG (http://www.geocities.co.jp/SiliconValley-Bay/4639/vbrelaxng/vbrelaxng.html)
For more information on available tools, check out http://www.relaxng.org/#software.
Before beginning the tutorial, install your chosen software according to its instructions and make sure you know how to actually validate a file.
This tutorial does assume a basic understanding of XML.