Declaring XML Attributes
Introduction
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 id ID #IMPLIED ref IDREF #IMPLIED >
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:
CDATAPlain-character data
IDA document-unique ID
IDREF, IDREFSA single value or list of values that must be equal to the value of an ID attribute within the document
NMTOKEN, NMTOKENSA single XML name token or list of tokens, respectively
ENTITY, ENTITIESA single declared entity name, or a list of names
NOTATIONA 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.
NOTE
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.