by Eric van der Vlist is published by O'Reilly & Associates (ISBN: 0596004214)

Introducing the Compact Syntax

Table of Contents

4.1. First Compact Patterns
4.1.1. The text Pattern
4.1.2. The attribute Pattern
4.1.3. Element
4.1.4. The optional Pattern
4.1.5. The oneOrMore Pattern
4.1.6. The zeroOrMore Pattern
4.2. Full Schema
4.3. XML or Compact?

Although the schema shown in Chapter 3 is simple, its XML representation is rather verbose. This is neither surprising nor uncommon for XML vocabularies. In fact it conforms to the basic principles of XML; the W3C Recommendation's design goals state that "XML documents should be human-legible and reasonably clear" and that "terseness in XML markup is of minimal importance." Our schema is a good example of a "human-legible and reasonably clear" document that's definitely not terse!

The principal goal of RELAX NG's XML syntax is to provide a serialization of RELAX NG schemas that can be processed by computers using standard XML toolkits. To make it easier for people to read and write RELAX NG schemas, however, James Clark introduced a second syntax that is strictly equivalent to the XML syntax, a more concise compact syntax.[1]

RELAX NG processors can support this compact syntax, but they aren't required to do so. If a RELAX NG processor doesn't support the compact syntax, you can translate the XML syntax to and from the compact syntax using existing translators. Because these two forms are strictly equivalent, there's no loss of information during translation. Even comments and annotations (presented in Chapter 13) are preserved in the process.


Syntactical details of XML, such as entity references or processing instructions, are lost when the XML syntax is translated into the compact syntax, but this is a limitation of the XML processing architecture rather than a limitation of RELAX NG itself.

You'll see that the compact syntax is built on a mix of concepts borrowed from the definition of structures in programming languages, notations from XML DTDs, and RELAX NG patterns. Element and attribute patterns look like Java declarations, with their curly brackets preceded by a reserved word, element or attribute, and their RELAX NG pattern name. Optionally, one or more, and zero or more elements or attributes are represented by DTD qualifier suffixes (? for optional, + for one or more, and * for zero or more).

The compact syntax is easy to use, especially (but not only) if you've ever worked with DTDs. You'll find the syntax intuitive, simple, and familiar before the end of this book. In this chapter, we'll explore the parts of the compact syntax that map to the RELAX NG patterns already discussed in Chapter 3. Later chapters introduce new components for the compact syntax along with their more verbose XML equivalents.

[1] The compact syntax has been published as an official OASIS RELAX NG committee specification but has not yet been submitted to ISO.

This text is released under the Free Software Foundation GFDL.