May 28, 2021 DTD
6. An element with a child element (sequence).
7. Declares an element that appears only once
8. Declares an element that appears at least once
9. Declares an element that appears zero or more times
10.. Declares elements that appear zero or once
In a DTD, elements are declared by element declarations.
In DTD, XML elements are declared by element declarations. Element declarations use the following syntax:
Empty elements are declared by the category keyword EMPTY:
<!ELEMENT element-name EMPTY>
实例:
<!ELEMENT br EMPTY>
XML example:
<br />
Only elements of PCDATA are declared by the #PCDATA in parentheses:
<!ELEMENT element-name (#PCDATA)>
实例:
<!ELEMENT from (#PCDATA)>
Elements declared by the category keyword ANY can contain any combination of resolvable data:
<!ELEMENT element-name ANY>
实例:
<!ELEMENT note ANY>
Elements with one or more child elements are declared by the child element name in parentheses:
<!ELEMENT element-name (child1)>
或
<!ELEMENT element-name (child1,child2,...)>
实例:
<!ELEMENT note (to,from,heading,body)>
When child elements are declared in a sequence separated by commas, they must appear in the document in the same order. I n a complete declaration, child elements must also be declared, and child elements can also have child elements. The full declaration of the "note" element is:
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT element-name (child-name)>
实例:
<!ELEMENT note (message)>
The above example states that the message child element must appear once, and only once in the "note" element.
<!ELEMENT element-name (child-name+)>
实例:
<!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.
<!ELEMENT element-name (child-name*)>
实例:
<!ELEMENT note (message*)>
The asterisk in the example above declares that the child element message can appear zero or more times within the "note" element.
<!ELEMENT element-name (child-name?)>
实例:
<!ELEMENT note (message?)>
Question mark in the example above (?) Declared: The child element message can appear zero or once within the "note" element.
实例:
<!ELEMENT note (to,from,header,(message|body))>
The example above states that the "note" element must contain the "to" element, the "from" element, the "header" element, and the non-"message" element, or the "body" element.
实例:
<!ELEMENT note (#PCDATA|to|from|header|message)*>
The example above states that the "note" element can contain PCDATA, "to," "from," "header," or "message" that occurs zero or more times.
Tip: Each of these types allows properties to be used in the element's starting tag.
Note: There is a principle in DTD that no explicit declaration is prohibited, and elements of the same name can only be declared once.