Apr 26, 2008

DTD Attribute List Definition

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:
o    <!ATTLIST FONT
o     %coreattrs; -- id, class, style, title --
o     %i18n; -- lang, dir --
o     size CDATA #IMPLIED -- [+|-]nn e.g. size="+1", size="4" --
o     color %Color; #IMPLIED -- text color --
o     face CDATA #IMPLIED -- comma-separated list of font names --
o     >
    • 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:
o    <!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:

  • #CURRENT - The first time an element appears, its type must be specified.

Other Keywords

  • NAME - "string of 1-8 characters (8 is a "default" limit); starting with a-z or A-Z, followed by a-z or A-Z, hyphen, period"
  • NAMES - "list of NAME values; each string separated by one or more spaces, tabs or returns ("separators")"
  • NUMBER - "a string of 1-8 characters consisting of the digits 0-9"
  • NUMBERS - "list of NUMBER values; each separated by a separator+."
  • NUTOKEN - "string of 1-8 characters beginning with 0-9 followed by a-z, A-Z, 0-9, hyphen, period."
  • NUTOKENS - "list of NUTOKEN values; each separated by a separator+"
  • "SYSTEM associates instructions or meaning with the new notation"

No comments:

Post a Comment

Popular Posts