Reputation: 21905
Let's say I have the following XML:
<data>
<authors>
<author>
<name>
<first_name>Stephen</first_name>
<last_name>Baxter</last_name>
</name>
</author>
<author>
<name>
<first_name>Joe</first_name>
<last_name>Haldeman</last_name>
</name>
<author>
</authors>
<books>
<book>
<name>The Time Ships</name>
</book>
<book>
<name>The Forever War</name>
<book>
</books>
</data>
In my DTD, how would I account for the fact that the "name" element is used for both authors and books and can have different child elements--like this?
<!ELEMENT name (#PCDATA|first_name,last_name)>
Upvotes: 4
Views: 3358
Reputation: 52888
Since your name
element is mixed content (both child elements or #PCDATA), you're going to have to change your element declaration to this:
<!ELEMENT name (#PCDATA|first_name|last_name)*>
This means that you are going to have to use something other than DTD to enforce that name
contains #PCDATA
or one first_name
followed by one last_name
.
Upvotes: 5