In the DTD, you declare lists of attributes in a manner similar to how you declare elements--by means of an attribute-list declaration.
The MouseOver shows the generic syntax for declaring an attribute, an attribute-list declaration, and an example of attribute usage.
Note the composition of the ID value in the XML file as required by its type:
The elementName represents the element for which the attribute (or attribute list) is being defined.
The attributeName represents the name of the attribute being declared. Attribute names can contain letters, numbers, dashes, underscores, periods and colons.
The attributeType specifies the kind of attribute this will be. There are eight types you can use when defining attributes; three are commonly used.
The attributeDefault represents whether the attribute is required (#REQUIRED) or optional (#IMPLIED), and whether it has a fixed value
(#FIXED value) or a specified default value from an enumerated list.
The ID attribute had to be present and had to be of the ID type.
The TYPE attribute was needed because the book would otherwise have been identified internally as having a "Hardcover" when in fact it was a "Paperback" type of book.
The STORELOC attribute was optional, and this file would have been valid with or without this attribute/value pair.
However, had any value other than "5th Avenue" been specified as the STORELOC attribute's value, this file would have been invalid.
The COMMENT attribute was not required, and no comment was added to the BOOK element.
The value for an ID type attribute cannot begin with a number. So while ID="1234" is not valid, ID= "A1234" is valid
Attribute syntax and usage
General Syntax and DTD Declaration
1. The elementName represents the element for which the attribute (or attribute list) is being defined.
2. The attributeName represents the name of the attribute being declared. Attribute names can contain letters, numbers, dashes, underscores, periods and colons.
3. The attributeType specifies the kind of attribute this will be. There are eight types you can use when defining attributes; three are commonly used. 4. The attributeDefault represents whether the attribute is required (#REQUIRED) or optional (#IMPLIED), and whether it has a fixed value
(#FIXED value) or a specified default value from an enumerated list.
5. The ID attribute had to be present and had to be of the ID type.
6. The TYPE attribute was needed because the book would otherwise have been identified internally as having a "Hardcover" when in fact it was a "Paperback" type of book.
7. The STORELOC attribute was optional, and this file would have been valid with or without this attribute/value pair.
However, had any value other than "5th Avenue" been specified as the STORELOC attribute's value, this file would have been invalid.
8. The COMMENT attribute was not required, and no comment was added to the BOOK element.
9. The value for an ID type attribute cannot begin with a number. So while ID="1234" is not valid, ID= "A1234" is valid
Attribute types
The table below contains the most commonly-used attribute types.
An IDREF holds the ID value of another element in the document. It is used to explore any relationships that may exit between different elements in an XML document.
For any attribute-list declaration, only one attribute can be specified as type ID.
Attribute Type
Description
CDATA
Can contain any kind of character data.
ID
Must have unique values within the element. For example, if you have three BOOK elements, and each has an ID attribute, the value of each ID type attribute within book elements must be unique. In the following example, TYPEID is of the ID type, and as such, requires unique values within the range of BOOK elements:
<BOOK TYPEID="ch1">See Spot Run</BOOK>
<BOOK TYPEID="ch2">Jack and Jill</BOOK>
(enumerated)
Specifies a default value if none was declared. Attributes can be defined to carry a list of accepted values. For example, in HTML, the ALIGN attribute can accept three values: left, center, and right. In the case of ALIGN with an enumerated list, left is the default value when none is specified.