XML Document Elements

The general syntax to declare an element is:

<!ELEMENT element content-model>

Here element is the element name, which is case-sensitive, must start with a letter or underscore, and cannot contain any spaces and reserved symbols like < or &. The content-model can take on only the following values:

Model Description Examples
EMPTY The element cannot store any content <!ELEMENT img EMPTY>
#PCDATA The element can contain only parsed character data, but no child elements <!ELEMENT name (#PCDATA)>
<name>John Nick Doe</name>
ANY The element can store any type of content (including parsed character data and child elements) and also can be empty <!ELEMENT products ANY>
<products>Digital camera</products>
<products />
<products>
  <name>Display</name>
  <type>NEC Multisync</type>
</products>
Elements The element can contain only specified child elements See examples below
Mixed The element can contain parsed character data and child elementsSee examples below

Working with child elements

The syntax for declaring the child elements is:

<!ELEMENT element (children_list)>
Example:
<!ELEMENT patient (phone)>
This allows the element to have only one child element phone, so the following document fragment will be invalid:
<patient>
  <name>Joe Doe</name>
  <phone>555-5555</phone>
</patient>

The child elements can form a list with a specified order of their appearance:

<!ELEMENT element (child1, child2, ...)>

Another way to list the child elements is to specify which ones can appear without declaring a specific order of their appearance:

<!ELEMENT element (child1 | child2 | ...)>

Character notations

One can also specify the number of times an element must appear:

Character Syntax Description
?message? can appear exactly 0 or 1 times
*message* can appear 0 or more times
+message+ can appear 1 or more times
|(x|y|z) | is used as the OR operator: only ONE element from the list can appear
()(x,y,z) () are used to group the set of values
,(x,y,z) comma indicates sequence: all elements must appear in specified order
Example:
The following declaration
<!ELEMENT customer (name, address, phone+, email?)>
forces one to provide for each customer their name, address, at least one phone number, and at most one (optional) email address in that specific order.
Example:
The following declaration
<!ELEMENT customers (name | company)+>
accepts a non-empty list of customers, each of which can be an individual or a company.

Working with mixed content

The mixed content allows an element to contain both parsed character data and child elements. The syntax is:

<!ELEMENT element (#PCDATA | child1 | child2 | ...)*>

The #PCDATA term must stay in the first place. While being the most relaxed and universal, this type of elements do not add much structure to your document, so they should be omitted in a very tightly structured document.