Relax NG

The educational technology and digital learning wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Definition

RELAX NG is an XML Schema language that represents a sort of compromise between the simplicity of DTDs and the complexity of W3C XML Schema.

According to the RELAX NG home page, its key features are that it:

  • is simple
  • is easy to learn
  • has both an XML syntax and a compact non-XML syntax
  • does not change the information set of an XML document
  • supports XML namespaces
  • treats attributes uniformly with elements so far as possible
  • has unrestricted support for unordered content
  • has unrestricted support for mixed content
  • has a solid theoretical basis
  • can partner with a separate datatyping language (such W3C XML Schema Datatypes)

The language

  • RELAX NG exists in two syntactic versions, an XML syntax and a short syntax.

Example

Copied from the Clark and Murato (2001) RELAX NG Tutorial.


Copyright © The Organization for the Advancement of Structured Information Standards [OASIS] 2001. All Rights Reserved.

This section and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works.

Consider a simple XML representation of an email address book:

<addressBook>
 <card>
   <name>John Smith</name>
   <email>js@example.com</email>
 </card>
 <card>
   <name>Fred Bloggs</name>
   <email>fb@example.net</email>
 </card>
</addressBook>

The DTD would be as follows:

<!DOCTYPE addressBook [
<!ELEMENT addressBook (card*)>
<!ELEMENT card (name, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>

A RELAX NG pattern for this could be written as follows:

<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
 <zeroOrMore>
   <element name="card">
     <element name="name">
       <text/>
     </element>
     <element name="email">
       <text/>
     </element>
   </element>
 </zeroOrMore>
</element>


Tools

  • Trang: multi-format schema converter based on RELAX NG. Trang supports the following languages: RELAX NG (both XML and compact syntax), XML 1.0 DTDs, W3C XML Schema. A schema written in any of the supported schema languages can be converted into any of the other supported schema languages, except that W3C XML Schema is supported for output only, not for input. Trang can also infer a schema from one or more example XML documents. Trang aims to produce human-understandable schemas; it tries to preserve all aspects of the input schema that may be significant to a human reader, including the definitions, the way the schema is divided into files, annotations and comments. Uses Jing. Implemented in Java. Written by James Clark. Open source (BSD license).
  • There was also a good converter from SUN, but SUN has well know trouble for keeping names and URLs in place ;)

Links

References

  • Clark, James and Murata, Makoto (2001), RELAX NG Tutorial, HTML
  • Clark, James and Murata, Makoto (2001), RELAX NG Specification, HTML
  • Eric van der Vlist (2002), Relax NG, Compared, xml.com, HTML