Dtd Attributes
* * *
In DTD, attributes are declared using the ATTLIST declaration.
* * *
## Declaring Attributes
Attribute declarations use the following syntax:
DTD Example:
XML Example:
```xml
The following are the options for **attribute types**:
| Type | Description |
| --- | --- |
| CDATA | The value is character data |
| (_en1_|_en2_|..) | The value must be one of the enumerated list |
| ID | The value is a unique ID |
| IDREF | The value is the ID of another element |
| IDREFS | The value is a list of other IDs |
| NMTOKEN | The value is a valid XML name |
| NMTOKENS | The value is a list of valid XML names |
| ENTITY | The value is an entity |
| ENTITIES | The value is a list of entities |
| NOTATION | The value is the name of a notation |
| xml: | The value is a predefined XML value |
Default **attribute values** can use the following values:
| Value | Explanation |
| --- | --- |
| Value | The default value of the attribute |
| #REQUIRED | The attribute value is required |
| #IMPLIED | The attribute is not required |
| #FIXED value | The attribute value is fixed |
* * *
## Default Attribute Values
DTD:
Valid XML:
```xml
In the above example, "square" is defined as an empty element with a "width" attribute of type CDATA. If the width is not specified, its default value is 0.
* * *
## #REQUIRED
### Syntax
### Example
DTD:
Valid XML:
```xml
Invalid XML:
```xml
If you do not have a default value option but still want to require authors to provide the attribute, use the keyword #REQUIRED.
* * *
## #IMPLIED
### Syntax
### Example
DTD:
Valid XML:
```xml
Valid XML:
```xml
If you do not want to force authors to include the attribute and you do not have a default value option, use the keyword #IMPLIED.
* * *
## #FIXED
### Syntax
### Example
DTD:
Valid XML:
```xml
Invalid XML:
```xml
If you want the attribute to have a fixed value and do not allow authors to change it, use the keyword #FIXED. If the author uses a different value, the XML parser will return an error.
* * *
## Enumerated Attribute Values
### Syntax
### Example
DTD:
XML Examples:
```xml
or
```xml
If you want the attribute value to be one of a set of fixed, valid values, use enumerated attribute values.
YouTip