DTD Basics   «Prev  Next»

Lesson 5Element type declarations
ObjectiveDeclare Basic Elements in a DTD.

Declare Basic Elements in DTD

The syntax for declaring an element in a DTD is as follows:
<!ELEMENT elementName (allowed element contents)> 

Element Names

Element names must begin with a letter but cannot begin with the letters "xml" in either upper or lower case. These three letters are reserved for the specification itself. In addition, you cannot use the colon character in an element name because it is reserved for other purposes.

Declaring Elements that contain Text or other elements

The keyword ANY is used to specify that an element can contain text or other elements using the following syntax:
<!ELEMENT elementName ANY> 

Here is an example DTD element declaration that declares the CREDIT-CARD element may contain either text or other elements:

Declaring elements that contain only text

When an element will contain only character data, declare the element in this manner:
<!ELEMENT elementName (#PCDATA)> 


If only #PCDATA is specified, any text (but only text) can be included in the declared element.
This requirement means that no child elements may be present in the element within which #PCDATA is specified.

Declaring Child Elements

When one element will contain other elements, this information must be specified in the element declaration. When an element contains multiple elements, you may use the DTD syntax characters outlined in the DTD symbols table. The table below contains DTD symbols and indicates the various symbols and their meanings in the context of DTDs:

Table displaying 1) Symbol, 2) Meaning, 3) Example, 4) Description of a DTD

The following Slide Show shows an example of how you specify information in the element declaration:

Information Declaration Element

Element Content

If an element will contain only child elements and no text other than those elements, it is said to have element content. The next lesson shows you how to write element declarations for mixed content.

Defining DTD - Quiz

Click the Quiz link below to check your understanding of DTD basics.
Defining DTD - Quiz