Latest web development tutorials

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 category>

<!ELEMENT element-name (element-content)>


Empty elements

Empty elements declared by category keyword EMPTY:

<!ELEMENT element-name EMPTY>

实例:

<!ELEMENT br EMPTY>

XML example:

<br />


Only PCDATA element

Only PCDATA elements inside parentheses #PCDATA declared:

<!ELEMENT element-name (#PCDATA)>

实例:

<!ELEMENT from (#PCDATA)>


Elements with no content

Statement by category keyword ANY element can contain any combination of parsable data:

<!ELEMENT element-name ANY>

实例:

<!ELEMENT note ANY>


Element has children (sequence)

Elements with one or more children elements inside parentheses child element names declared:

<!ELEMENT element-name (child1)>

<!ELEMENT element-name (child1,child2,...)>

实例:

<!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 note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>


Statement elements appear only once

<!ELEMENT element-name (child-name)>

实例:

<!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 element-name (child-name+)>

实例:

<!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 element-name (child-name*)>

实例:

<!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 element-name (child-name?)>

实例:

<!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 ... / ... 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".