Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 533
His Avatar asked Jan 24 '26 02:01

His


1 Answers

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.

like image 184
jasso Avatar answered Jan 25 '26 21:01

jasso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!