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>
CDATA | Attribute value contains only character data. |
ID | Attribute value is unique |
IDREF | The attribute value refers to the ID type attribute of another element |
IDREFS | The attribute contains multiple values separated by a whitespace and each value refers to the ID type attribute of another element |
ENTITY | The attribute value contains the name of an unparsed entity declared in the same DTD |
ENTITIES | The attribute value contains multiple unparsed entities, separated by whitespaces |
NMTOKEN | The 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 |
NMTOKENS | The attribute value contains multiple name tokens separated by whitespace |
Enumerated | Enumerated 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 |
#IMPLIED | This means the attribute is optional. The element may or may not contain this attribute |
#REQUIRED | This means the attribute is required for all instances of the element |
#FIXED | The 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
Nothing yet..be the first to share wisdom.