Chapter 4. Introducing the Compact Syntax
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.
Tip
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.
Get RELAX NG now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.