3

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.

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
His
  • 5,891
  • 15
  • 61
  • 82
  • I could be mistaken that this is the error, but after resolving `%text;` you have two parentheses nested. – Boldewyn May 10 '10 at 14:01
  • Hmmm, is having two parentheses nested an invalid thing in an XML DTD? Not sure. But if I remove the `#PCDATA` from the `%text;` entity declaration, so it becomes `<!ENTITY % text "(L)*">`, the DTD becomes valid. – His May 10 '10 at 14:11

1 Answers1

8

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.

jasso
  • 13,736
  • 2
  • 36
  • 50