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.


Recursive models

As mentioned in the introduction of this chapter, named patterns are the only way to represent recursive models. We don't yet have all the building blocks needed to define a recursive XHTML div element, for example, but we'll start with a simpler example. If our library is divided into categories, each of them havinga title, zero or more embedded category elements and zero or more books, we could write (assuming that named patterns have been defined for the book element:

 <define name="category">
  <element name="category">
   <element name="title">
    <text/>
   </element>
   <zeroOrMore>
    <ref name="category"/>
   </zeroOrMore>
   <zeroOrMore>
    <ref name="book"/>
   </zeroOrMore>
  </element>
 </define>

Or:

 category = element category{
  element title{text},
  category *,
  book*
 }

Note that in this case, the recursive reference to the category named pattern must be optional. Otherwise the document would be required to have an infinite depth!


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.