Table of Contents

About

The element structure of an XML document may, for validation purposes, be constrained using:

declarations defined in the doctype:

These declarations may be contained in whole or in part within parameter entities

Declaration Type

Element type

Definition

An element type declaration constrains the element's content.

Element type declarations often constrain which element types can appear as children of the element.

An XML processor may issue a warning when a declaration mentions an element type for which no declaration is provided, but this is not an error.

Syntax

<!ELEMENT Name contentspec>

where:

  • name gives the element type
  • contentspec is one of the following specification:
empty

empty element declaration

<!ELEMENT br EMPTY>
any
<!ELEMENT container ANY>
mixed

mixed content declarations:

<!ELEMENT p (#PCDATA|a|ul|b|i|em)*>
<!ELEMENT p (#PCDATA | %font; | %phrase; | %special; | %form;)* >
<!ELEMENT b (#PCDATA)>

The keyword #PCDATA derives historically from the term “parsed character data.”

children (relationship)

element content model

Declaration Relationship (Cardinality)
<!ELEMENT master (child)> One and only once
<!ELEMENT master (child+)> One or more
<!ELEMENT master (child*)> Zero or more
<!ELEMENT master (child?)> Zero or one

Example:

<!ELEMENT spec (front, body, back?)>
<!ELEMENT div1 (head, (p | list | note)*, div2*)>
<!ELEMENT dictionary-body (%div.mix; | %dict.mix;)*>

where the cardinality operator:

  • one or more (+),
  • zero or more (*),
  • or zero or one times (?).
  • (default|absence): once

Attribute-list

Attribute-list declarations specify:

  • the name,
  • data type,
  • and default value (if any)

of each attribute associated with a given element type.

Example with doctype:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TABLE [
        <!ELEMENT TABLE (ROW)*>
        <!ATTLIST ROW COL1 CDATA #IMPLIED>
        <!ATTLIST ROW COL2 CDATA #IMPLIED>
        <!ELEMENT ROW (#PCDATA)>
        ]>
<TABLE>
    <ROW COL1="25874" COL2="000005" />
    <ROW COL1="26084" COL2="000006" />
</TABLE>