If you need to use a quotation mark, percent sign, or ampersand in your parameter or general entity strings, you must use character or general entity references-for example, ", %, &, or ", and &. (There is no predefined entity for the percent sign, but you could create a general or parameter entity for it.)
Declaring an internal parameter entity
The syntax for declaring an internal parameter entity is shown here:
<!ENTITY % name "string_of_characters">
As you can see, the syntax for declaring an internal parameter entity is only slightly different from that used for declaring internal general entities-a percent sign is used in front of the entity name. (The percent sign must be preceded and followed by a white space character.)
In Chapter 4, we created a sample DTD for a static HTML page. If you want to create a dynamic page, you will probably want to add forms and other objects to your DTD. There is a standard set of events associated with all of these objects, but instead of listing the events for every declaration of every object, you could use the following parameter entity in your DTD:
<!ENTITY % events "onclick CDATA #IMPLIED ondblclick CDATA #IMPLIED onmousedown CDATA #IMPLIED onmouseup CDATA #IMPLIED onmouseover CDATA #IMPLIED onmousemove CDATA #IMPLIED onmouseout CDATA #IMPLIED onkeypress CDATA #IMPLIED onkeydown CDATA #IMPLIED onkeyup CDATA #IMPLIED" >
This code declares a parameter entity named events that can be used as an attribute for all of your objects that have these attributes.
You could have also declared a parameter entity named Script, and then used it within the events parameter entity declaration, as shown here:
<!ENTITY % Script "CDATA"> <!ENTITY % events "onclick %Script; #IMPLIED ondblclick %Script; #IMPLIED >
The Script parameter entity allows you to use data type names that are more readable than just using CDATA. Although this code is more readable, some XML tools (such as XML Authority) cannot accept parameter entities used in this way. Be aware of this limitation if you use this technique.
Using internal parameter entities
The events parameter entity will be used in the attribute declaration of the form objects and in other elements, such as body. To reference a parameter entity, you must precede the entity with a percent sign and follow it with a semicolon. For example, you could now make this declaration:
<!ATTLIST body alink CDATA #IMPLIED text CDATA #IMPLIED bgcolor CDATA #IMPLIED link CDATA #IMPLIED vlink CDATA #IMPLIED %events; onload CDATA #IMPLIED onunload CDATA #IMPLIED >
In this case, the internal parameter entity %events; has been added to the body element's attribute declaration. The parameter entity events could be used in any declaration in which these events are allowed.