I need a DTD which allows an element A to have 0, 1 or 2 child-elements B. I tried it with
<!ELEMENT A (B? |(B,B))>
but then i get an error:
validity error : Content model of A is not determinist
what is the problem and how can i solve it? or isn't it possible to solve it with DTD?
Content models such as
(B? |(B,B))
or
(B?, B?)
or
(B? | (B,B) | B)
are non-deterministic; the parser cannot tell which B is being matched without looking ahead to see what follows it.
Non-deterministic content models are disallowed in the XML 1.0 recommendation: http://www.w3.org/TR/xml/#determinism. However, the determinism requirement is there for compatibility with SGML. I guess that this may help in explaining differences in behaviour between XML parsers:
See also: What is the reason for not allowing non-deterministic element declarations in DTDs and XSD schemas?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With