Attributes
An attribute is a mechanism for adding descriptive information to an element. For example, in our patient record XML document, we have no idea whether the patient's weight is measured in pounds or kilograms. To indicate that PatientWeight is given in pounds, we would add a unit attribute and specify its value as LB:
<PatientWeight unit="LB">155</PatientWeight> |
Attributes can be included only in the begin tag, and like elements they are case-sensitive. Attribute values must be enclosed in double quotation marks (").
Attributes can be used with empty elements, as in the following well-formed example:
<PatientWeight unit="LB"/> |
In this case, this might mean that the patient weight is unknown or it has not yet been entered into the system.
An attribute can be declared only once in an element. Thus, the following element would not be well formed:
<PatientWeight unit="LB" unit="KG">155</PatientWeight> |
This makes sense because the weight cannot be both kilograms and pounds.