Element Declarations

Every element used in an XML document must have an Element Declaration included in the Document Type Declarations. Element declarations have the following syntax:

<!ELEMENT name element_content >

Element declarations begin with the delimitter <!ELEMENT and ends with the delimiter >

The <!ELEMENT delimiter is followed by the element name, which can be any valid XML name.

element_content defines the content of the element which can be text, child elements, empty or mixed content.

#PCDATA

An element that contains only plain text is defined using the keyword #PCDATA (for Parsed Character Data) inside parenthesis.
Example :

<!ELEMENT title (#PCDATA)>

Child Elements

Elements that contain child elements are defined by the name of the child element inside parenthesis. Multiple child elements are separated by comma.
Example :

<!ELEMENT catalog (movie)>
<!ELEMENT movie (title,year,genre,director)>

In the above example, the catalog element is declared to contain only one child element of type movie. The movie element contains child elements title, year, genre, director in the exact same sequence.

To declare zero or more child elements you use the * operator after the child element name.
Example :

<!ELEMENT catalog (movie*)>

This means the catalog element contains zero or more child elements of type movie

To declare one or more child elements you use the + operator after the child element name.
Example :

<!ELEMENT catalog (movie+)>

This means the catolog element must have at least one child element of type movie

To declare optional child elements you use the ? operator after the child element name.
Example :

<!ELEMENT movie (actor?)>

This means the movie element may or may not contain a child element of type actor

EMPTY

Elements that do not have any content are defined using the keyword EMPTY.
<!ELEMENT picture EMPTY>

ANY

The keyword ANY is used to declare that the element can contain any data.
Example:

<!ELEMENT catalog ANY>

The catalog element can contain any content including child elements.

Last Updated: 18-February-2014


Post a comment

Name

Your Comment

Email (We dont publish it)

Comments

Nothing yet..be the first to share wisdom.