DTD Elements

Home » Scripting » XML » DTD Elements

Declaring an Element

In the DTD, XML elements are declared with an element declaration.

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

Empty Elements

Empty elements are declared with the category keyword EMPTY:

<!ELEMENT element-name (EMPTY)>

example:

<!ELEMENT img (EMPTY)>
<!ELEMENT element-name EMPTY>

Example:

<!ELEMENT br EMPTY>

XML example:

<br /> 

Elements with data

Elements with data are declared with the data type inside parentheses:

<!ELEMENT element-name (#CDATA)>
or
<!ELEMENT element-name (#PCDATA)>
or
<!ELEMENT element-name (ANY)>

example:

<!ELEMENT note (#PCDATA)>

Elements with data

Elements with data are declared with the data type inside parentheses:

<!ELEMENT element-name (#CDATA)>
or
<!ELEMENT element-name (#PCDATA)>
or
<!ELEMENT element-name (ANY)>

example:

<!ELEMENT note (#PCDATA)>

#CDATA means the element contains character data that is not supposed to be parsed by a parser.

#PCDATA means that the element contains data that IS going to be parsed by a parser.

The keyword ANY declares an element with any content.

If a #PCDATA section contains elements, these elements must also be declared.