Search code examples
xmldtdxml-validationpcdata

Why is this not a valid XML DTD? (Parameter entity and #PCDATA)


Using the DTD validator here, I am informed that the following DTD is invalid.

<!ENTITY % text "(#PCDATA|L)*">
<!ELEMENT H         (%text;)+>
<!ELEMENT L         (#PCDATA)>

The error message is: "A '(' character or an element type is required within declaration of element type "H"." at line 2, column 22.

Can anyone please point out why it is invalid? And how can I make it valid? The error message is not exactly very friendly to me. Thanks.


Solution

  • You cannot enforce that an element with mixed content must have at least one child node. Your DTD becomes

    <!ELEMENT H         ((#PCDATA|L)*)+>
    

    when the entity is expanded. The only allowed form for elements with mixed content is

    (#PCDATA | A | B | C)*
    

    where A, B and C are possible child elements. #PCDATA must be the first choice and the set must be allowed to repeat 0-infinity times, i.e. the asterisk is required.