ELEMENT tag

ELEMENT tag

An ELEMENT tag contains:
<!ELEMENT this-element (its-contents)>
Note that the ELEMENT tag is somewhat similar to the DOCTYPE tag:

  • there is an exclaimation point ! before the word ELEMENT
  • ELEMENT tag does NOT have a closing tag
  • ELEMENT tag does NOT have a slash/ at the end
  • ELEMENT is in upper case letters
  • the element being defined is specified immediatly after the word ELEMENT
  • then the contents of this element are specified
  • the contents must be in (parentheses).

An element can have any of the following five kinds of content.

  • element - only contains elements
  • text - only contains text
  • mixed - may contain text, as well as elements
  • empty - contains nothing
  • any - unspecified - anything is allowed - this is not generally used

We will look at each of these five kinds of ELEMENT tags.

element content

single element

An element can be specified to only contain one other element.

In the source of the example to the left, you can see:
<!ELEMENT name (last) >
This means the   name   element conains exactly one   last   element.

sequence of elements, in order

An element can be specified to contain a sequence of elements, in order.

In the source of the example to the left, you can see:
<!ELEMENT name (first, middle, last) >
Note:   the list of elements are seperated by commas.
This means the   name   element conains one   first   element, followed by one   middle   element, followed by one   last   element.

choice

An element can be specified to contain one element from a set of choices.

In the source of the example to the left, you can see:
<!ELEMENT student (name | student-id | ssn) >
Note:   the set of choices are seperated by vertical bars |
This means the   name   element conains exactly one of the three alternative elements.

parentheses

Parentheses can be used to put a choice within a sequence, or other similar constructions.

In the source of the example to the left, you can see:
<!ELEMENT name (first, (middle-name | middle-initial), last) >
This means either the   middle-name   or the   middle-initial   element can be used in the sequence.

repetition

An element or parentheses can be followed by a repetition mark. The repetition marks are:

  • ? zero or one occurrence
  • * zero or more occurrences
  • + one or more occurrences

In the source of the   ? zero or one   example to the left, you can see:
<!ELEMENT name (first, middle?, last) >
This means the   middle   element is optional.

In the source of the   * zero or more   example to the left, you can see:
<!ELEMENT name (first, middle*, last) >
This means the   middle   element is optional, and can be repeated.

In the source of the   + one or more   example to the left, you can see:
<!ELEMENT name (first, middle, last+) >
This means the   last   element must occur at least once, and can be repeated.

text content

text

An element can be specified to only contain text.

In the source of the example to the left, you can see:
<!ELEMENT name (#PCDATA) >
This means the   name   element conains text. #PCDATA means the text data is parsed.

mixed content

mixed

An element can be specified to contain a mixture of text and elements.

In the source of the example to the left, you can see:
<!ELEMENT name (#PCDATA|first|last)* >
This means the   name   element conains a mixture of text,   first   elements, and   last   elements, in any order, repeated any number of times. #PCDATA means the text data is parsed.
NOTE:   #PCDATA must be first, before the elements in the selection set.

empty

empty

An element can be specified as EMPTY.

In the source of the example to the left, you can see:
<!ELEMENT name EMPTY >
This means the   name   element is EMPTY.

any

any

An element can be specified as ANY.

In the source of the example to the left, you can see:
<!ELEMENT name ANY >
This means the   name   element can contain any elements that have been specified, in any order, repeated any number of times..