December 2003
Intermediate to advanced
506 pages
12h 26m
English
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.
Read now
Unlock full access