A declaration for a parameter internal parsed entity has the following general form:
<!ENTITY % EntityName EntityValue>
Here, EntityName is the name of the entity. You can select any name, provided that you follow these rules:
■ The name must begin with a letter or underscore (_), followed by zero or more letters, digits, periods (.), hyphens (-), or underscores.
■ The XML specification states that names beginning with the letters xml (in any combination of uppercase or lowercase letters) are “re-served for standardization.” Although Internet Explorer doesn’t en-force this restriction, it’s better not to begin names with xml to avoid future problems.
■ Remember that case is significant in all text within markup, includ-ing entity names. Thus, an entity named Spot is a different entity than one named spot.
EntityValue is the value of the entity. The value you assign a parameter internal entity is a series of characters delimited with quotes, known as a quoted string or literal. You can assign any literal value to a parameter internal entity, provided that you observe these rules:
■ The string can be delimited using either single quotes (') or double quotes (").
■ The string cannot contain the same quotation character used to de-limit it.
■ The string cannot include an ampersand (&) except to begin a char-acter or general entity reference. Nor can it include the percent sign (%) (for an exception, see the sidebar “An Additional Location for Parameter Entity References” on page 151).
146 XML Step by Step
The entity file contains the entity’s replacement text, which must consist of com-plete markup declarations of the types allowed in a DTD—specifically, element type declarations, attribute-list declarations, entity declarations, notation decla-rations, processing instructions, or comments. (I described these types of markup declarations in “Creating the Document Type Definition” in Chapter 5.) You can also include parameter entity references between markup declara-tions, and you can include IGNORE and INCLUDE sections. I described IG-NORE and INCLUDE sections in “Conditionally Ignoring Sections of an External DTD Subset” in Chapter 5. (For exceptions to the guidelines given in this paragraph, see the sidebar “An Additional Location for Parameter Entity References” on page 151.)
note
In a parameter external entity file, you can optionally include a text declaration in addition to the entity’s replacement text. The text declaration must come at the very beginning of the file. For information, see the sidebar “Characters, Encoding, and Languages” on page 77.
You can use parameter external entities to store groups of related declarations.
Say, for example, that your business sells books, CDs, posters, and other items.
You could place the declarations for each type of item in a separate file. This would allow you to combine these groups of declarations in various ways. For instance, you might want to create an XML document that describes only your inventory of books and CDs. To do this, you could include your book and CD declarations in the document’s DTD by using parameter external entities, as shown in this example XML document:
<?xml version=”1.0"?>
<!DOCTYPE INVENTORY
Chapter 6 Defining and Using Entities 147
6Defining Entities
<INVENTORY>
<BOOK>
<BOOKTITLE>The Marble Faun</BOOKTITLE>
<AUTHOR>Nathaniel Hawthorne</AUTHOR>
<PAGES>473</PAGES>
</BOOK>
<CD>
<CDTITLE>Concerti Grossi Opus 3</CDTITLE>
<COMPOSER>Handel</COMPOSER>
<LENGTH>72 minutes</LENGTH>
</CD>
<BOOK>
<BOOKTITLE>Leaves of Grass</BOOKTITLE>
<AUTHOR>Walt Whitman</AUTHOR>
<PAGES>462</PAGES>
</BOOK>
<!— additional items... —>
</INVENTORY>
Here are the contents of the Book.dtd entity file:
<!ELEMENT BOOK (BOOKTITLE, AUTHOR, PAGES)>
<!ELEMENT BOOKTITLE (#PCDATA)>
<!ELEMENT AUTHOR (#PCDATA)>
<!ELEMENT PAGES (#PCDATA)>
And here are the contents of the CD.dtd entity file:
<!ELEMENT CD (CDTITLE, COMPOSER, LENGTH)>
<!ELEMENT CDTITLE (#PCDATA)>
<!ELEMENT COMPOSER (#PCDATA)>
<!ELEMENT LENGTH (#PCDATA)>
Notice that a parameter external entity works much like an external DTD sub-set. Parameter external entities, however, are more flexible—they allow you to include several external declaration files and to include them in any order. (Re-call that an external DTD subset is always processed after the entire internal DTD subset has been processed.)
150 XML Step by Step
Entity type Form of entity reference, Places where you can insert where EntityName is the an entity reference (example) name of the entity
General external EntAttr=’EntityName’ ■ You can’t insert a reference unparsed where EntAttr is an to this type of entity, but
ENTITY or ENTITIES you can identify the entity type attribute by assigning its name to an
attribute that has the ENTITY or ENTITIES type (see “Declaring a General External Unparsed Entity”) Parameter internal %EntityName; ■ In a DTD where markup
parsed declarations can occur, not
within markup declarations (for an exception, see the sidebar “An Additional Location for Parameter Entity References” follow-ing this table) (see “Declar-ing a Parameter Internal Parsed Entity”)
Parameter external %EntityName; ■ In a DTD where markup
parsed declarations can occur, not
within markup declarations (for an exception, see the sidebar “An Additional Location for Parameter Entity References” follow-ing this table) (see “Declar-ing a Parameter External Parsed Entity”)
Character 	 or &#xh; ■ In an element’s content (see reference where 9 is the numeric “Inserting Character
code for the character References”) continued
Chapter 6 Defining and Using Entities 151
6Defining Entities