DTD Attributes

Just as you need to define all elements in your DTD, you also need to define any attributes they use. You use the <!ATTLIST> declaration to define attributes in your DTD.

Syntax

You use a single <!ATTLIST> declaration to declare all attributes for a given element. In other words, for each element (that contains attributes), you only need one <!ATTLIST> declaration.

The <!ATTLIST> declaration has the following syntax:

Here, element_name refers to the element that you're defining attributes for, attribute_name is the name of the attribute that you're declaring, TYPE is the attribute type, and DEFAULT_VALUE is it's default value.

Example

Here, we are defining an attribute called published for the tutorial element. The attribute's type is CDATA and it's default value is No.