RELAX NG by Eric van der Vlist will be published by O'Reilly & Associates (ISBN: 0596004214)

You are welcome to use our annotation system to give your feedback.


First compact patterns

Let's explore how the patterns described in the previous chapter translate into the compact syntax.

The optional pattern is formalized as a trailing ? added after a definition, as is true in DTDs as well. For example, to define that the attribute id is optional we would write:

 attribute id { text }?

Note that the qualifier ? must be added after the definition of the pattern but before the delimiter. If we used this in the larger definition of our author element, it would therefore look like this:

    element author { attribute id { text }, element name { text }, element born { text
}?, element died { text }? }

In Chapter 3, we mentioned that other combinations of what is optional and what is not could be described using the optional pattern as a container. In the compact syntax, the optional pattern is represented as a qualifier rather than a container, so we need a container if we need to create the same combinations. The container is the parenthesis (...). The effect of parentheses depends on the optional qualifier following them. Parentheses without a qualifier are effectively transparent; they do nothing. The definition of our author could be written:

    element author {( attribute id { text }, element name { text }, element born
{ text }?, element died { text }? )}

or

    element author { (attribute id { text }), (element name { text }),
(element born { text })?, (element died { text }?) }
 without changing its meaning at all. They are more useful (and actually even required)
to write the combinations mentioned in the previous chapter. Combinations like:
 <optional> <element name="born"> <text/> </element>
<element name="died"> <text/> </element> </optional>

would translate as:

      (element born { text }, element died { text })?

while

 <optional> <element name="born"> <text/>
</element> <optional> <element name="died"> <text/> </element>
</optional> </optional>

Would translate into:

      (element born { text }, element died { text }? )?

The oneOrMore pattern is also a qualifier and, in the DTD tradition it is a +:

    element author { attribute id { text }, element name { text }, element born
{ text }?, element died { text }? }+

Last but not least, the zeroOrMore pattern is the * qualifier:

    element character { attribute id { text }, element name { text }, element born {
text }?, element qualification { text } }*

You are welcome to use our annotation system to give your feedback.
[Annotations for this page]
All text is copyright Eric van der Vlist, Dyomedea. During development, I give permission for non-commercial copying for educational and review purposes. After publication, all text will be released under the Free Software Foundation GFDL.