Attributes

Let me use an example from the previous textbook for this module:

<actor actorid="HF1234" gender="male" type="superstar">
    Harrison Ford
</actor>

The DTD part for this bit might look as follows

<!ELEMENT actor (#PCDATA)>
<!ATTLIST actor
    actorid ID #REQUIRED
    gender (male|female) #REQUIRED
    type CDATA #IMPLIED>

CDATA means character data ie any string of alphanumerics. CDATA is very liberal.

#IMPLIED means optional. Logical or not, it does. We see that gender is #REQUIRED, the very opposite of optional. We must use it when writing an XML document observing this DTD. It takes only one of two possible values, the enumeration stipulates taht values may be male, or female. Nothing else.

The attribute actorid is defined as ID meaning something similar to a key from the relational model. Values of IDs must obey rules known from variable names in most programming languages, it must start with an alphabetic and may be followed by any alphabetic or numeric. You may come across the type IDREF occasionally. IDREF is an equivalent of a foreign key from the relational world, a unique identifier.