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">
  <text/>
 </element>
</define>

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.

Groups of identical attributes on different element types
Figure 5-2. 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">
  <text/>
 </element>
 <optional>
  <element name="born">
   <text/>
  </element>
  </optional>
</define>

or:

common-content =
  attribute id { text },
  element name { text },
  element born { text }?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.63.61