Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

DTD Elements

DTD - Elements


In a DTD, elements are declared with an element declaration.


Declaring an element

In a DTD, XML elements are declared with an element declaration. Element declarations use the following syntax:

or


null Element

Empty elements are declared with the category keyword EMPTY:

Example:

XML example:



Elements with only PCDATA

Elements with only PCDATA are declared with #PCDATA inside parentheses:

Example:


Elements with any content

Elements declared with the category keyword ANY may contain any combination of parsable data:

Example:


Elements with child elements (sequences)

Elements with one or more child elements are declared by listing the child element names inside parentheses:

or

Example:

When child elements are declared as a sequence separated by commas, they must appear in the document in the same order. In a complete declaration, the child elements must also be declared, and they may have child elements of their own. The complete declaration of the "note" element is:


Declaring an element that appears exactly once

Example:

The example above declares that the message child element must appear once, and only once, inside the "note" element.


Declaring an element that appears at least once

Example:

The plus sign (+) in the example above declares that the message child element must appear at least once inside the "note" element.


Declaring an element that appears zero or more times

Example:

The asterisk (*) in the example above declares that the message child element may appear zero or more times inside the "note" element.


Declaring an element that appears zero or one time

Example:

The question mark (?) in the example above declares that the message child element may appear zero or one time inside the "note" element.


Declaring "either/or" content

Example:

The example above declares that the "note" element must contain the "to", "from" and "header" elements, and either the "message" element or the "body" element.


Declaring mixed content

Example:

The example above declares that the "note" element may contain zero or more occurrences of PCDATA, "to", "from", "header" or "message".