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


The choice Pattern

Let's add some flexibility to the name element so we can accept:

<name>Lucy</name>

and:

<name>
 <first>Charles</first>
 <middle>M</middle>
 <last>Schulz</last>
</name>

and:

<name>
 <first>Peppermint</first>
 <last>Patty</last>
</name>

To express this flexibility, use a choice pattern that accepts either a text node or a group of three elements (one of which is optional):

<element name="name">
 <choice>
  <text/>
  <group>
   <element name="first"><text/></element>
   <optional>
     <element name="middle"><text/></element>
   </optional>
   <element name="last"><text/></element>
  </group>
 </choice>
</element>

The compact syntax uses a pipe, or logical "or" character (|) to denote choices:

 element name {
  text|(
   element first{text},
   element middle{text}?,
   element last{text}
  )}

Note that you have to use parentheses to mark the boundary of the group pattern.


This text is released under the Free Software Foundation GFDL.