DTD - Element
In a DTD, elements are declared through element declarations.
Declaring an Element
In a DTD, XML elements are declared through element declarations. Element declarations use the following syntax:
Empty Element
Empty elements are declared using the keyword EMPTY:
Elements Containing Only PCDATA
Elements containing only PCDATA are declared with #PCDATA in parentheses:
Elements Containing Any Content
Elements declared with the keyword ANY can contain any combination of parseable data:
Elements with Child Elements (Sequence)
Elements with one or more child elements are declared with the child element names in parentheses:
When child elements are declared in a sequence separated by commas, they must appear in the same order in the document. In a complete declaration, child elements must also be declared, and they can have their own child elements. The complete declaration for the "note" element is:
Declaring an Element That Occurs Exactly Once
The above example declares that the message child element must occur once and only within the "note" element.
Declaring an Element That Occurs at Least Once
The plus sign (+) in the above example declares that the message child element must occur at least once within the "note" element.
Declaring an Element That Occurs Zero or More Times
The asterisk (*) in the above example declares that the message child element can occur zero or more times within the "note" element.
Declaring an Element That Occurs Zero or Once
The question mark (?) in the above example declares that the message child element can occur zero or once within the "note" element.
Declaring "Either...or..." Type Content
The above example declares that the "note" element must contain the "to" element, "from" element, "header" element, and either the "message" element or the "body" element.
Declaring Mixed Content
The above example declares that the "note" element can contain zero or more occurrences of PCDATA, "to", "from", "header", or "message".