The ELEMENT
statement is used to declare each element used within the document type defined by the DTD. It first declares the element by name, and then specifies what content is allowed for the element.
<!ELEMENT name content >
The following table displays the reserved keyword or punctuation symbols that can be used along with names of other elements that are declared within the DTD to construct the element content rule.
Symbols | Description |
---|---|
#PCDATA | Allows parsed character data as part of the content of the element. |
name | The name of an element. This can be the element being defined, or other elements defined by name in the DTD, using additional ELEMENT declarations.
If there are no other punctuation markers or symbols in the content rule, one and only one occurrence of the named element is allowed and required. |
() | Although at least one set of parentheses is required whenever declaring a content model for an element, you can nest additional sets of parentheses as well. This technique can be used to define a more complex content model for an element. |
| | A vertical bar can be used to separate two named elements. When used, it indicates that either element (i.e. the one before the bar or the one after it) can appear as child elements. |
, | The comma can be used to separate two named elements or nested rules. When used, it indicates that the elements/rules must appear in the order specified. |
? | The question mark can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is optional, but if it is used it can occur only once at this point in the XML document structure. |
+ | The plus sign can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is required, and can occur more than once at this point in the XML document structure. |
* | The asterisk can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is optional, and can occur more than once at this point in the XML document structure. |
<test>
element that can contain any content:
<!ELEMENT test ANY >
<Image>
element that must be empty (i.e. cannot have content):
<!ELEMENT Image EMPTY >
<title>
element that can contain character data only (no other markup):
<!ELEMENT title (#PCDATA) >
<fruit>
element that contain either an <apple>
element or an <orange>
element:
<!ELEMENT fruit (apple|orange) >
<book>
element that must contain an <author>
element followed by a <title>
element:
<!ELEMENT book (author,title) >
<memo>
element that must contain a <body>
element which can be optionally followed by a <postscript>
element:
<!ELEMENT memo (body,postscript?) >
<catalog>
element that must contain one or more <book>
elements:
<!ELEMENT catalog (book+) >
<table>
element that can either be empty or contain <rowset>
elements:
<!ELEMENT table (rowset*) >
ATTLIST (Attribute List) | ENTITY | NOTATION