Next / Previous / Contents / TCC Help System / NM Tech homepage

5. Attribute declarations

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:

    <!ATTLIST ename {aname atype default} ...>

where ename is the name of the element for which you're defining attributes, aname is the name of one of that element's possible attributes, atype describes what values it can have, and default describes whether it has a default value. The last three items can be repeated inside an <!ATTLIST...> declaration, one group per attribute.

The atype part describing the attribute's type can have three kinds of values:

The last part of the declaration, default, specifies whether the attribute can be omitted, and what value it will have if omitted. This must be one of the following:

#REQUIRED

The attribute must always be supplied.

#IMPLIED

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.

"value"

The attribute can be omitted, and the default value is the quoted string that you provide.

#FIXED "value"

The attribute must be given and must have the given "value".

5.1. Tokenized attributes

You can restrict an attribute to have only values with a certain structure. Here are the possible values of the atype part of the attribute declaration for such attributes:

ID

An ID attribute must be a unique identifier for that node. This allows other nodes to refer to it. The attribute value must also be a valid XML name (see above).

IDREF

An IDREF attribute is a reference to an ID attribute in a different node.

For example, suppose that in your DTD, there is a <sailor> element with an ID-type nickname attribute, and another element <duty> with an IDREF-type attribute called sailor-nick. Then if you have an element like this:

    <sailor nickname='Bluto'>...</sailor>

then this tag would refer to that element:

    <duty sailor-nick='Bluto'>...</duty>
IDREFS

The value of an IDREFS attribute must contain one or more ID references separated by spaces. Example:

    <roster sailor-nicks='Bluto Popeye Olive_Oyl'/>
ENTITY

Use this attribute type to refer to external, non-parsed entities. See the section on notations, below.

ENTITIES

Like ENTITY, but the attribute can be a list of one or more entity names separated by spaces.

NMTOKEN

The attribute value must be a name token, conforming to the rules for XML names (see above).

NMTOKENS

Like NMTOKEN, but the attribute value can contain one or more name tokens separated by spaces.