Specifying Attributes
Added 26 Jul 2008
Adding attributes to an existing DTD is easy. For each attribute, you need to specify which element it goes with, what the attribute name is, what type of values it may have, and whether the attribute is optional or not. This information is specified in this model:
elementName attributeName type optionalStatus
>
To add the maxlength attribute to the
element, you write this:
The CDATA specification means that the attribute value
can contain any old character data you please; thus
maxlength="300" or maxlength="ten" will both
be valid. For “open-ended” data, DTDs don’t let you
get more specific. The #IMPLIED specification means that
the attribute is optional. A required attribute would specify
#REQUIRED.
When you have a list of possible values for an attribute, you may specify
them in the DTD. This is the case with the attribute named
required,
which has the values true and false. The values
are case sensitive; in this example only the lowercase values are specified, so
a value of TRUE would not be considered valid.
Confusion alert! This attribute is named “required,”
but you don’t have to put it on every
element, so it’s an optional attribute.
The attribute named required should also be available to the
and elements. All
in all, the specifications to modify the DTD look like this: