XML

Attribute Declaration

Posted on 25th February 2014

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.

Syntax

<!ATTLIST element_name attribute_name data_type default>

Example

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

Post a comment

Comments

Nothing yet..be the first to share wisdom.