The general syntax to declare an element is:
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 elements | See examples below |
The syntax for declaring the child elements is:
The child elements can form a list with a specified order of their appearance:
Another way to list the child elements is to specify which ones can appear without declaring a specific order of their appearance:
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 |
The mixed content allows an element to contain both parsed character data and child elements. The syntax is:
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.