<!ENTITY name value>
<!ENTITY % name value>
The first version creates a general entity; the second, because of
the percent sign, creates a parameter entity.
For both entity types, the name is simply a sequence of characters
beginning with a letter, colon, or underscore, and followed by any
combination of letters, numbers, periods, hyphens, underscores, or
colons. The only restriction is that names may not begin with the
sequence "xml" (either upper or lowercase).
The entity value is either a character string within quotes (unlike
HTML markup, you must use quotes even if it is a string of contiguous
letters) or a reference to another document containing the value of
the entity. For these external entity values, you'll find
either the keyword SYSTEM, followed by the URL of the document
containing the entity value, or the keyword PUBLIC, followed by the
formal name of the document and its URL.
A few examples will make this clear. Here is a simple general entity
declaration:
<!ENTITY fruit "kumquat or other similar citrus fruit">
In this declaration, the entity "&fruit;"
within the document will be replaced with the phrase "kumquat
or other similar citrus fruit" wherever it appears.
Similarly, here is a parameter entity declaration:
<!ENTITY % ContentType "CDATA">
Here is an external general entity declaration:
<!ENTITY boilerplate SYSTEM "http://server.com/boilerplate.txt">
It tells the XML processor to retrieve the contents of the file
boilerplate.txt from
server.com and use it as the value of the
boilerplate entity. Anywhere you use
&boilerplate; in your document, the contents
of the file will be inserted as part of your document content.
Here is an external parameter entity declaration, lifted from the
HTML DTD, that references a public external document:
<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "xhtml-lat1.ent">
causes all of those general entities to be defined as part of the
language.
A DTD author can use the PUBLIC and SYSTEM external values with
general and parameter entity declarations. You should structure your
external definitions to make your DTDs and documents easy to read and
understand.
You'll recall that we began the section on entities with a
mention of unparsed entities whose only purpose is to be used as
values to certain attributes. You declare an unparsed entity by
appending the keyword NDATA to an external general entity
declaration, followed by the name of the unparsed entity. If we
wanted to convert our general boilerplate entity to an unparsed
general entity for use as an attribute value, we could say: