Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

DTD element


May 28, 2021 DTD


Table of contents


DTD - Element

In I n DTD, element (ELEMENT) is used to constrain tags, defining a tag with an element declaration, which is declared with the message , " ELEMENT" starts with ""

In a DTD, elements are declared by element declarations.


Declare an element

In DTD, XML elements are declared by element declarations. Element declarations use the following syntax:

<! E LEMENT element-name category; or slt;! ELEMENT element-name (element-content)>

Empty element

Empty elements are declared by the category keyword EMPTY:

<!ELEMENT element-name EMPTY>

实例:

<!ELEMENT br EMPTY>

XML example:

<br />

Only elements of PCDATA

Only elements of PCDATA are declared by the #PCDATA in parentheses:

<!ELEMENT element-name (#PCDATA)>

实例:

<!ELEMENT from (#PCDATA)>

An element with anything

Elements declared by the category keyword ANY can contain any combination of resolvable data:

<!ELEMENT element-name ANY>

实例:

<!ELEMENT note ANY>

An element with a child element (sequence).

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

Declares an element that appears only once

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


Declares an element that appears at least once

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


Declares an element that appears zero or more times

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


Declares elements that appear zero or once

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


Declares content of the "non-.../i.e...." type

实例:

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


Declare mixed content

实例:

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