Java Reference
In-Depth Information
This indicates that the value of
diameter
is
2
if the attribute is not specified for a
<circle>
element.
You can also insist that a value for an attribute must be one of a fixed set. For example, suppose you had
a
color
attribute for your circle that could be only red, blue, or green. You could define it like this:
<!ATTLIST circle
color (red|blue|green) #IMPLIED
>
The value for the
color
attribute in a
<circle>
element must be one of the options between the par-
entheses. In this case the attribute can be omitted because it is specified as
#IMPLIED
, and an application
processing it supplies a default value. To make the inclusion of the attribute mandatory, you define it as
<!ATTLIST circle
color (red|blue|green) #REQUIRED
>
An important aspect of defining possible attribute values by an enumeration like this is that an XML ed-
itor can help the author of a document by prompting with the list of possible attribute values from the DTD
when the element is being created.
An attribute that you declare as
#FIXED
must always have the default value. For example:
<!ATTLIST circle
color (red|blue|green) #REQUIRED
line_thickness medium #FIXED
>
Here the XML processor supplies an application only with the value
medium
for the
thickness
attribute.
If you were to specify this attribute for the
<circle>
element in the body of the document you could use
only the default value; otherwise, it is an error.
Defining Parameter Entities
You often need to repeat a block of information at different places in a DTD. A
parameter entity
identifies a
block of parsed text by a name that you can use to insert the text at various places within a DTD. Note that
parameter entities are for use only within a DTD. You cannot use parameter entity references in the body
of a document. You declare general entities in the DTD when you want to repeat text within the document
body.
The form for a parameter entity is very similar to what you saw for general entities, except that a
%
char-
acter appears between
ENTITY
and the entity name, separated from both by a space. For example, it is quite
likely that you would want to repeat the
x
and
y
attributes that you defined in the
<position>
element in
the previous section in other elements. You could define a parameter entity for these attributes and then use
that wherever these attributes appear in an element declaration. Here's the parameter entity declaration:
<!ENTITY % coordinates "x CDATA #REQUIRED y CDATA #REQUIRED">
Now you can use the entity name to insert the
x
and
y
attribute definitions in an attribute declaration:
<!ATTLIST position %coordinates; >