Element declarations

Element declarations are the core of the DTD. Every element must have an element declaration in order for the document to validate. Consider the parts of this declaration for the title element.

<!ELEMENT title (#PCDATA)>

!ELEMENT identifies the line as an element declaration (no surprise there). The next part provides the element name (in this case, title) that will be used in the markup tag. Finally, the material within the parentheses identifies the content model for the element, or in other words, what type of content it may contain. In this example, the content model for the title element must be #PCDATA, which stands for parsed character data. This means the content is character data that may or may not include escaped character entities (such as &lt; and &amp; for < and &, respectively), but it may not include other elements.

Other content models include:

Single child elements

You may also put other element names in the parentheses. In the following (non-XHTML) element declaration, the content of the birth element must be exactly one year element.

<!ELEMENT birth (year)>
Sequences

More often, elements will contain multiple elements. When element names are separated by commas in the parentheses, it means they must appear in exactly the provided order. No listed element may be omitted or the document will be invalid.

<!ELEMENT birth (month, year)>
The number of child elements

DTD syntax allows you to indicate varying numbers of element instances using the following ...

Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.