balimaco00
balimaco00

Reputation: 85

A DTD Element with EMPTY and PCDATA

Can we declare an element in DTD like that :

<!ELEMENT name (EMPTY | (#PCDATA))>

Thank you

Upvotes: 2

Views: 2214

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52888

If you are trying to declare an element that is either empty or could contain character data (text) then no, you cannot declare an element like that.

See "contentspec" from the specs:

[46]      contentspec    ::=      'EMPTY' | 'ANY' | Mixed | children

You could declare an element like:

<!ELEMENT name (#PCDATA|EMPTY)*>

but that is saying name contains mixed content (both character data and child elements). In this case the possible child is an element named EMPTY.

You should declare the element like this:

<!ELEMENT name (#PCDATA)>

This will allow name to contain character data or be empty.

For example, the following name elements would all be valid:

<name></name>
<name/>
<name>balimaco00</name>

Upvotes: 5

Related Questions