Java Reference
In-Depth Information
OPERATOR DESCRIPTION
+
This operator indicates that there can be one or more occurrences of its operand. In other words, there
must be at least one occurrence, but there may be more.
This operator indicates that there can be zero or more occurrences of its operand. In other words, there
can be none or any number of occurrences of the operand to which it applies.
*
This indicates that its operand may appear once or not at all.
?
This operator indicates that there can be an occurrence of either its left operand or its right operand, but
not both.
|
You might want to allow a building number or a building name in an address, in which case the DTD
could be written as follows:
<!ELEMENT address ((buildingnumber | buildingname), street, city, state, zip?)>
<!ELEMENT buildingnumber (#PCDATA)>
<!ELEMENT buildingname (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zip (#PCDATA)>
The DTD now states that either <buildingnumber> or <buildingname> must appear as the first element
in <address> . But you might want to allow neither, in which case you would write the third line as the fol-
lowing:
<!ELEMENT address ((buildingnumber | buildingname)?, street, city, state, zip?)>
The ? operator applies to the parenthesized expression (buildingnumber | buildingname) , so it now
states that either <buildingnumber> or <buildingname> may or may not appear, so you allow one, or the
other, or none.
Of course, you can use the | operator repeatedly to express a choice between any number of elements, or
indeed, subexpressions between parentheses. For example, given that you have defined elements Linux ,
Solaris , and Windows , you might define the element operatingsystem as
<!ELEMENT operatingsystem (Linux | Solaris | Windows)>
If you want to allow an arbitrary operating system to be identified as a further alternative, you could write
<!ELEMENT operatingsystem (AnyOS | Linux | Solaris | Windows)>
<!ELEMENT AnyOS (#PCDATA)>
You can combine the operators you've seen to produce definitions for content of almost unlimited com-
plexity. For example:
<!ELEMENT breakfast ((tea|coffee), orangejuice?,
((egg+, (bacon|sausage)) | cereal) , toast)>
This states that <breakfast> content is either a <tea> or <coffee> element, followed by an optional
<orangejuice> element, followed by either one or more <egg> elements and a <bacon> or <sausage> ele-
ment, or a <cereal> element, with a mandatory <toast> element bringing up the rear. However, while you
can produce mind-boggling productions for defining elements, it is wise to keep things as simple as pos-
sible.
Search WWH ::




Custom Search