To enforce the attribution properties of a tag, you must add an attribute-list-declaration to the document's DTD. This list accomplishes the following:
The general attribute syntax is:
<!ATTLIST element attribute1 type1 default1
attribute2 type2 default2
attribute3 type3 default3 ...>
Here element is the element name associated with the attribute, attribute is the attribute name, type is the attribute's data type, and default indicates whether the attribute is required and whether it has a default value. In practice, this declaration can be split into several single ones, each describing a specific attribute:
XML supports 9 attribute types, we consider only 4 of them here:
| Type | Description |
|---|---|
| CDATA | character data |
| enumerated list | a list of possible attribute values |
| ID | a unique text string |
| IDREF | a reference to an ID value |
CDATA allows an attribute to contain almost any data except some reserved symbols like <, >, &.
In some cases you'll want to restrict the set of possible attribute values. You can do it with the following syntax:
An ID token is used whenever the attribute value must be unique in the document. Ones an ID is defined, other attribute values can reference to it by using the IDREF token.
There are 4 possible values listed in the following table:
| Value | Description |
|---|---|
| #REQUIRED | the attribute must appear with every occurrence of the element |
| #IMPLIED | the attribute is optional |
| "default" | the attribute is optional; if its value is not specified, the XML parser set it up with the default value |
| #FIXED default | the attribute is optional; if its value is specified, it must match the default value |