Home > Articles > Web Services > XML

Declaring XML Attributes

  • Print
  • + Share This
Scott Means discusses attribute types and declarations in a DTD.
This article is excerpted from Strategic XML by W. Scott Means (Sams, 2001, ISBN 0-672-32175-0).
From the author of

From the author of


Just as the element declaration in a DTD limits the contents of a particular element, the attribute declaration controls which and what type of attributes can be included in a particular element.

The <!ATTLIST> markup tag is used to control the attributes that can be included in a particular element. As an example, here's the attribute declaration for the item element:

<!ATTLIST item

The first name token after the <!ATTLIST> markup is the name of the element associated with this declaration. Following the element name is a triplet list of attribute name, type, and default value. Multiple <!ATTLIST> declarations can be given for a single element throughout the DTD. The result is the same as if all the declarations were combined into a single large declaration.

In a single triple, the first token is the name of the attribute to be declared. The second token is the attribute type, which must come from the following list:

  • CDATA—Plain-character data

  • ID—A document-unique ID

  • IDREF, IDREFS—A single value or list of values that must be equal to the value of an ID attribute within the document

  • NMTOKEN, NMTOKENS—A single XML name token or list of tokens, respectively

  • ENTITY, ENTITIES—A single declared entity name, or a list of names

  • NOTATION—A single name from an enumeration of declared notation names

In addition to these types, it's possible to declare an attribute that is limited to a list of valid values.

The most frequently used attribute types by far are CDATA, ID, and IDREF.


The full attribute declaration syntax is much too complex to be covered here. For a detailed explanation of valid attribute declarations, consult a complete XML reference.

  • + Share This
  • 🔖 Save To Your Account