To
enforce attribution properties of elements, you must add an attribute-list
declaration to the DTD. The attribute-list declaration lists the names
of all attributes; specifies the data type of all attributes; indicates
whether the attribute is required or optional; and provides a default
value if necessary. The syntax is as follows:
<!ATTLIST element attribute1 type1 default1
attribute2 type2 default2
attributet type 3 default3...>
OR
<!ATTLIST ELEMENT attribute1 type1 default1>
<!ATTLIST ELEMENT attribute2 type2 default2>
<!ATTLIST ELEMENT attribute3 type3 default3>
Attribute Types
Type |
Syntax |
String |
attribute CDATA |
Enumerated (list of possible values) |
attribute (value1 | value2 | value3)
|
Tokenized (valid XML name) |
attribute token
ID - unique identifier for the attribute
IDREF - references id of another element
IDREFS - a list of id references separated by spaces
NMTOKEN - name token whose value is restricted to a valid XML
name
ENTITY - a reference to an external file (i.e. non-XML data)
ENTITIES - a list of entity references separated by spaces |
Default Values
There are four possible defaults:
Attribute Default |
Syntax |
#REQUIRED |
<!ATTLIST Customer CustID ID #REQUIRED> |
#IMPLIED |
<!ATTLIST Customer CustType (home | business)
#IMPLIED> |
"default" |
Optional value. Syntax to have parser assume
a value:
<!ATTLIST Item ItemQty CDATA "1"> |
#FIXED "default" |
Optional value. If an attribute value is specified,
it must match the default value.
|