css| Standard | Web page
In a DTD, XML elements are declared through a DTD element declaration.
Declaring an Element
In DTDs, XML elements are declared through element declarations. Element declarations use the following syntax:
<! Element element name Category >
Or
<! Element elements name (element content) >
Empty element
Empty elements are declared by category keyword empty:
<! Element name Empty>
Example:
<! ELEMENT BR empty>
XML Example:
<br/>
Only pcdata elements.
Only pcdata elements are declared through the #pcdata in parentheses:
<! Element name (#PCDATA) >
Example:
<! ELEMENT from (#PCDATA) >
Elements with content
The element that is declared by the category keyword any can contain a combination of any resolvable data:
<! Element name Any>
Example:
<! ELEMENT Note any>
Elements with child elements (sequences)
Elements with one or more child elements are defined by the name of the child element in parentheses:
<! element name (child element name) >
Or
<! element name (child element name, child element name,.....) >
Example:
<! ELEMENT Note (to,from,heading,body) >
When child elements are declared in a comma-delimited sequence, the child elements must appear in the document in the same order. In a complete declaration, child elements must also be declared, and child elements can also have child elements. The complete declaration of the "note" element is:
<! ELEMENT Note (to,from,heading,body) ><! ELEMENT to (#PCDATA) ><! ELEMENT from (#PCDATA) ><! ELEMENT heading (#PCDATA) ><! ELEMENT body (#PCDATA) >
To declare an element that appears only once
<! element name (child element name) >
Example:
<! ELEMENT Note >
The example above declares that the message child element must appear once, and must appear once in the "note" element.
Declare elements that appear at least once
<! element name (child element name +) >
Example:
<! ELEMENT Note (message+) >
The plus sign in the example above declares that the message child element must appear at least once within the "note" element.
Declare an element that appears 0 or more times
<! element name (child element name *) >
Example:
<! ELEMENT Note (message*) >
The asterisk in the example above declares that the child element message can appear 0 or more times within the "note" element.
Declare an element that appears 0 times or once
<! element name (child element name?) >
Example:
<! ELEMENT note (message?) >
The question mark in the above example declares that the child element message can appear 0 or one times within the "note" element.
Declare "Non .../..." type of content
Example:
<! ELEMENT Note (To,from,header, (message|body)) >
The above example declares that the "note" element must contain a "to" element, a "from" element, "header" element, and a "body" element that is not a "message" element.
Declaring a mixed type of content
Example:
<! ELEMENT Note (#PCDATA |to|from|header|message) *>
The above example declares that the "note" element can contain pcdata, "to", "from", "header", or "message" that appear 0 or more times.