Element Attributes
The final piece of the DTD puzzle involves attributes. You know
attributes: they are the name/value pairs included with tags in your
documents that control the behavior and appearance of those tags. To
define attributes and their allowed values within an XML DTD, use the
<!ATTLIST> directive:
<!ATTLISTelementattributes>
The element is the name of the element
to which the attributes apply. The attributes
are a list of attribute declarations for the element. Each attribute
declaration in this list consists of an attribute name, its type, and
its default value, if any.
Attribute Values
Attribute values can be of several types, each denoted in an attribute definition with one of the following keywords:
CDATAIndicates that the attribute value is a character or string of characters. This is the attribute type you would use to specify URLs or other arbitrary user data. For example, the
srcattribute of the<img>tag in HTML has a value ofCDATA.IDIndicates that the attribute value is a unique identifier within the scope of the document. This attribute type is used with an attribute, such as the HTML
idattribute, whose value defines an ID within the document, as discussed in "Core Attributes" in Appendix B.IDREForIDREFSIndicate that the attribute accepts an ID defined elsewhere in the document via an attribute of type
ID. You use theIDtype when defining IDs; you useIDREFandIDREFSwhen referencing a single ID and a list of IDs, respectively.ENTITYorENTITIESIndicate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access