| In a DTD, I need to specify that an element can have a sequence of
| exactly 7, 8, or 9 instances of another element. Would the following
| be "valid"?
| <!ELEMENT XYZ (x, x, x, x, x, x, x, x?, x?)>
* Andrew Webber
| Part of the problem is that if an eighth "x" appears in the
| instance, there's no way to know if a ninth is allowed (was that
| eighth "x" right after the last required one, or was the first
| required one ommitted?).
This is actually incorrect. The only problem with the above content
model is that it is not compatible with SGML. Writing the necessary
code to decide whether a given sequence of elements does or does not
match the above content model is straightforward.
True, the content model is ambiguous in that after 8 "x"s you don't
know where you are in the content model. But the overall
interpretation is perfectly clear: 7, 8 or 9 "x"s are allowed, but no
In fact, when implementing validation in the mathematically obvious
way (as a finite automaton) checking for ambiguity requires extra work.
| This approach solves that, by explicitly stating that if an eighth
| "x" is seen, where it falls, and whether a ninth is allowed:
| <!ELEMENT XYZ (x, x, x, x, x, x, x, (x, x?)?)>
This approach removes the 'ambiguity', yes.