Java Reference
In-Depth Information
+
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.
We might want to allow a building number or a building name in an address, in which case the DTD
could be written:
<!DOCTYPE address
[
<!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 we might want to allow neither, in which case we would write the third line as:
<!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 we 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 wanted 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 we have seen to produce definitions for content of almost unlimited
complexity. For example:
Search WWH ::




Custom Search