DTD element
In a DTD, element by element declaration to be declared.
Declare an element
In a DTD, XML element by element declaration to be declared. Element declaration with the following syntax:
或
<!ELEMENT element-name (element-content)>
Empty elements
Empty elements declared by category keyword EMPTY:
实例:
<!ELEMENT br EMPTY>
XML example:
<br />
Only PCDATA element
Only PCDATA elements inside parentheses #PCDATA declared:
实例:
<!ELEMENT from (#PCDATA)>
Elements with no content
Statement by category keyword ANY element can contain any combination of parsable data:
实例:
<!ELEMENT note ANY>
Element has children (sequence)
Elements with one or more children elements inside parentheses child element names declared:
或
<!ELEMENT element-name (child1,child2,/en.)>
实例:
<!ELEMENT note (to,from,heading,body)>
When the sub-elements separated by commas according to the sequence of statements, these sub-elements must appear in the same order in the document. In a full declaration, the children must also be declared, but also child elements can have child elements. "Note" element is the complete statement:
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Statement elements appear only once
实例:
<!ELEMENT note (message)>
The above example declares: message the child elements must appear once, and must appear only once in the "note" element.
Declaration element appears at least once
实例:
<!ELEMENT note (message+)>
The example above the plus sign (+) declares: message the child elements must appear at least once in the "note" element.
Zero or more element declarations appear
实例:
<!ELEMENT note (message*)>
The above examples asterisk (*) declares: child element message can appear in the "note" element zero or more times.
Declaring zero or one element
实例:
<!ELEMENT note (message?)>
The above example declares question mark (?): The child element message can appear in the "note" element zero or one time.
Statement "Non /en. / /en. both" types of content
<!ELEMENT note (to,from,header,(message|body))>
The above example declares: "note" element must contain a "to" element, "from" element, "header" element, as well as non "message" element only "body" element.
Content declaration hybrid
<!ELEMENT note (#PCDATA|to|from|header|message)*>
The above example declares: "note" element can contain zero or more times PCDATA, "to", "from", "header" or "message".