Attribute Declaration

A valid XML document must declare all the attributes of an element using ATTLIST declarations. Multiple attributes of an element can be declared using a single declaration. ATTLIST declarations contain the elements name, followed by the list the attributes that an element can have, data type of the attribute and default value for the attribute.


<!ATTLIST element_name attribute_name data_type default>
  • element_name : Name of the element for which the attributes apply
  • attribute_name : Name of the attribute
  • data_type : Data type of the attribute must be one of the following:
    CDATAAttribute value contains only character data.
    IDAttribute value is unique
    IDREFThe attribute value refers to the ID type attribute of another element
    IDREFSThe attribute contains multiple values separated by a whitespace and each value refers to the ID type attribute of another element
    ENTITYThe attribute value contains the name of an unparsed entity declared in the same DTD
    ENTITIESThe attribute value contains multiple unparsed entities, separated by whitespaces
    NMTOKENThe attribute value is a name token which allows the data to contain letters, numbers, and some punctuation marks like underscore, hyphen, period and colon. Whitespaces are not allowed
    NMTOKENSThe attribute value contains multiple name tokens separated by whitespace
    EnumeratedEnumerated is not a keyword for this type of data instead it is a list of all possible values for an attribute enclosed in parentheses and separated by vertical bars in the attribute declaration
  • default The possible values for attribute defaults are:
    #IMPLIEDThis means the attribute is optional. The element may or may not contain this attribute
    #REQUIREDThis means the attribute is required for all instances of the element
    #FIXEDThe attribute must always have value that is specified immediately after this keyword


The following example declares the attributes for the movie element

<!ATTLIST movie
	Title   CDATA     #REQUIRED
	Genre  CDATA     #IMPLIED
	Language   (English |French |Chinese)  "English"
	Format   CDATA     #FIXED    "DVD"

Title attribute contains only character data and is required for all movie elements;
Genre is an optional attribute of type character data;
Language can have value English, French or Chinese; default is English if this attribute is not set for an element;
The value Format attribute is fixed for all movie elements and the value is DVD

Last Updated: 25-February-2014

Post a comment


Your Comment

Email (We dont publish it)


Nothing the first to share wisdom.