DTD Attribute List Definition

ATTLIST

This defines an attribute list for an element. It defines the available attributes the element can have. ATTLIST syntax:

<!ATTLIST ElementName AttName AttType DefaultValue>

The ElementName is the name of the element for which the list of attributes are being defined. The parts of the attribute declaration include:

  • AttName - The the name of the attribute being defined.
  • AttType - Defines the type of data that may be used for the value such as CDATA (character data). The attribute type values may include:
    • CDATA - Used to specify a string type. The HTML 4 transitional DTD uses the CDATA word as follows:
      <!ATTLIST FONT
       %coreattrs; -- id, class, style, title --
       %i18n; -- lang, dir --
       size CDATA #IMPLIED -- [+|-]nn e.g. size="+1", size="4" --
       color %Color; #IMPLIED -- text color --
       face CDATA #IMPLIED -- comma-separated list of font names --
       >
      
    • ENTITY - Reference to an external file such as a graphic file for importing an image. Used for a tokenized type.
    • ENTITIES - Used to include multiple entities. Used for a tokenized type.
    • ID - There can be only one unique value used in a tokenized type.
    • IDREF - Used as a reference to another element with an attribute value with the ID value set. Used for a tokenized type.
    • IDREFS - Used as a reference to more than one element with an attribute value with the ID value set. Used for a tokenized type. The attribute values referenced may be of the form (in the DTD):

      <!ATTLIST Object Unique ID #REQUIRED Reference IDREFS #IMPLIED

      The XML element declaration:

      <Object Unique'"N03" Reference="N01 N02">

    • NMTOKEN - A name token similar to an ID token. Used for a tokenized type.
    • NMTOKENS - A list of multiple name tokens. Used for a tokenized type.
    • NOTATION - Used to identify a program to process a type of data format or identify the type of data format. This must match a notation declaration as declared by a NOTATION keyword in the DTD (See the NOTATION section). An example:
      <!ATTLIST MYDOC texttype NOTATION  ( tex | pl ) #REQUIRED>
      
    • (name1 | name2) - Used for an enumerated type, this is a list with name tokens as shown in the HTML DTD for the HR element below:

      align (left|center|right) #IMPLIED

  • Default Value - Specifies the value of the attribute name if its value is not otherwise defined. The possible values are:
    • The character data (CDATA) default value of the attribute in a quoted string form.
    • #FIXED - Used to fix a default value of the attribute.
    • #IMPLIED - Optional
    • #REQUIRED - One value is required.

The AttName, AttType, and DefaultValue may be repeated in the attribute liste in order to define multiple attributes for the element. Here's an example of an attribute list for the HR element from the HTML 4 transitional DTD:

<!ATTLIST HR
 %attrs; -- %coreattrs, %i18n, %events --
 align (left|center|right) #IMPLIED
 noshade (noshade) #IMPLIED
 size %Pixels; #IMPLIED
 width %Length; #IMPLIED
 >

This example uses several ENTITIES, which are name definitions. The comment:

-- %coreattrs, %i18n, %events --

is indicating that the entities %coreattrs, %i18n, %events are contained within the %attrs entity. This is defined earlier by the line:

<!ENTITY % attrs "%coreattrs; %i18n; %events;">

As you may notice there are special words such as implied in the ATTLIST declarations. Their meanings are:

Other Keywords

DTD Contents Page