Parentheses
Individually, choices, sequences, and suffixes are fairly limited. However,
they can be combined in arbitrarily complex fashions to describe
most reasonable content models. Either a choice or a sequence can be
enclosed in parentheses. When so enclosed, the choice or sequence
can be suffixed with a ?,
*, or +. Furthermore, the parenthesized item can
be nested inside other choices or sequences.
For example, let’s suppose you want to say that a circle element contains a center element and either a radius or a diameter element, but not both. This
declaration does that:
<!ELEMENT circle (center, (radius | diameter))>
To continue with a geometry example, suppose a center element can either be defined in
terms of Cartesian or polar coordinates. Then each center contains
either an x and a y or an r and a θ. We would declare this using two small
sequences, each of which is parenthesized and combined in a
choice:
<!ELEMENT center ((x, y) | (r, θ))>Suppose you don’t really care whether the x element comes before the y element or vice versa, nor do you care
whether r comes before . Then you
can expand the choice to cover all four possibilities:
<!ELEMENT center ((x, y) | (y, x) | (r, θ) | (θ, r) )>
As the number of elements in the sequence grows, the number of permutations grows more than exponentially. Thus, this technique really isn’t practical past two or three child elements. DTDs are not very good at saying you want n instances of A and m instances of B, but you don’t really ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access