Attributes Entitites   «Prev  Next»

Lesson 3Attribute-list declaration syntax
Objective Declare lists of attributes.

Attribute-list Declaration Syntax

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:
DTD attribute list
  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 Syntax Usage

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.
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.
The next lesson defines the entities in a DTD.