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

Defining Named Patterns

RELAX NG uses named patterns to address both modularity and recursion. Named patterns are reusable patterns that can be referenced by their name.

In the XML syntax, named patterns are defined using define elements. To define named patterns that contain the title element, write:

<define name="title-element">
 <element name="title">

The compact syntax uses a construction similar to a programming language format. The same definition would be written in the compact syntax as:

title-element = element title {text}

You're not limited to embedding a single element or attribute definition in a named pattern. Note that the group shown in Figure 5-2, an id attribute, a name element, and an optional born element are present in the same order and with the same definition in both the author and the character element.

Figure 5-2. Groups of identical attributes on different element types

Groups of identical attributes on different element types

To define a named pattern for this group, write:

<define name="common-content">
 <attribute name="id"/>
 <element name="name">
  <element name="born">


common-content =
  attribute id { text },
  element name { text },
  element born { text }?

This text is released under the Free Software Foundation GFDL.