DTD Attribute Default Values
In the example in the previous lesson, we defined an attribute using a default value of "No". In this lesson, we look at the various options for defining default values for your attributes.
Default Values
The attribute TYPE field can be set to one of the following values:
| Value | Description |
|---|---|
| value | A simple text value, enclosed in quotes. |
| #IMPLIED | Specifies that there is no default value for this attribute, and that the attribute is optional. |
| #REQUIRED | There is no default value for this attribute, but a a value must be assigned. |
| #FIXED value | The #FIXED part specifies that the value must be the value provided. The value part represents the actual value. |
Examples of these default values follow.
value
You can provide an actual value to be the default value by placing it in quotes.
Syntax:
<!ATTLIST element_name
attribute_name CDATA "default_value">
Example:
<!ATTLIST tutorial
published CDATA "No">
#REQUIRED
The #REQUIRED keyword specifies that you won't be providing a default value, but that you require that anyone using this DTD does provide one.
Syntax:
<!ATTLIST element_name
attribute_name CDATA #REQUIRED>
Example:
<!ATTLIST tutorial
published CDATA #REQUIRED>
#IMPLIED
The #IMPLIED keyword specifies that you won't be providing a default value, and that the attribute is optional for users of this DTD.
Syntax:
<!ATTLIST element_name
attribute_name CDATA #IMPLIED>
Example:
<!ATTLIST tutorial
rating CDATA #IMPLIED>
#FIXED
The #FIXED keyword specifies that you will provide value, and that's the only value that can be used by users of this DTD.
Syntax:
<!ATTLIST element_name
attribute_name CDATA #FIXED "value">
Example:
<!ATTLIST tutorial
language CDATA #FIXED "EN">
