If an element is to have attributes, the names and possible values of those attributes must be declared in the DTD. Here is the general form:
the name of the element for which you're defining
the name of one of that element's possible attributes,
describes what values it can have, and
describes whether it has a default value. The last three
items can be repeated inside an
<!ATTLIST...> declaration, one
group per attribute.
part describing the attribute's type can have three kinds
CDATA means that
the attribute can have any character string as a
For example, suppose you want every
<play> element to have
title attribute that can
contain any text, and that attribute is required. Here is
the complete attribute declaration:
<!ATTLIST play title CDATA #REQUIRED>
There are several tokenized attribute types, which are required to have a certain structure. See tokenized attributes below.
You can provide a specific set of legal values for the attribute; see enumerated attributes below.
The last part of the declaration,
specifies whether the attribute can be omitted, and what
value it will have if omitted. This must be one of the
The attribute must always be supplied.
The attribute can be omitted, and the DTD does not provide a default value. Anyone reading this file may assume a default value, but that is not the DTD's problem.
The attribute can be omitted, and the default value is the quoted string that you provide.
The attribute must be given and must have the given
You can restrict an attribute to have only values
with a certain structure. Here are the possible values
part of the attribute declaration for such
ID attribute must be
a unique identifier for that node. This allows other
nodes to refer to it. The attribute value must also
valid XML name
IDREF attribute is a
reference to an
in a different node.
For example, suppose that in
your DTD, there is a
<sailor> element with an
nickname attribute, and another
IDREF-type attribute called
sailor-nick. Then if you have
an element like this:
then this tag would refer to that element:
The value of an
attribute must contain one or more
ID references separated by
<roster sailor-nicks='Bluto Popeye Olive_Oyl'/>
Use this attribute type to refer to external, non-parsed entities. See the section on notations, below.
the attribute can be a list of one or more
entity names separated by spaces.
The attribute value must be a name token, conforming to the rules for XML names (see above).
NMTOKEN, but the
attribute value can contain one or more name
tokens separated by spaces.