Reputation: 29026
I'm trying to generate a DTD and I was wondering how to allow child elements to contain elements that have already been declared in the DTD. Do you have to declare them again? As an example:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE document [
<!ELEMENT document (author,title,body)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT body (br*,hr*,img*,table*)>
<!ELEMENT br EMPTY>
<!ELEMENT hr EMPTY>
<!ELEMENT img EMPTY>
<!ELEMENT table (tr+)>
<!ELEMENT tr (td+)>
<!ELEMENT td (#PCDATA)>
<!--hr element-->
<!ATTLIST hr width CDATA "0">
<!--img element-->
<!ATTLIST img height CDATA "0">
<!ATTLIST img src CDATA #REQUIRED>
<!ATTLIST img width CDATA "0">
<!--td element-->
<!ATTLIST td width CDATA "0">
]>
<document>
<author>My Author</author>
<title>My Title Test</title>
<body>
<hr />
<table>
<tr>
<td>Would like elements here</td>
</tr>
</table>
</body>
</document>
In the above XML, I'd like to, for example, allow the br, hr, img and table tags to be within the td tag. Do I have to redefine those elements in the DTD?
I appreciate any help and thank you in advance.
Upvotes: 1
Views: 2365
Reputation: 39485
you should reference them in the <!ELEMENT td>
definition
edit: if you want to maintain the parsed character data in the td element along with the new tags, you can define a mixed content element. example:
<!ELEMENT td (#PCDATA | br? | hr? | img?)>
see element declarations at w3.org
Upvotes: 2