Recursive Models

As mentioned earlier, 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 let’s start with a simpler example. If our library is divided into categories, each having a title, zero or more embedded category elements, and zero or more books, you can 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 is required to have an infinite depth!

..................Content has been hidden....................

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