Parameter Entities
Parameter entities are used exclusively within DTDs. Parameter entities accomplish the same task as the other entities do, i.e. acting as a shortcut. Using parameter entities you can include element and attribute list declarations as groups and refer to them easily as single entities. You can even include an entire DTD in a parameter entity.
Parameter entities distinguish themselves from other entities by the inclusion of one simple character. The percent sign (% ), in the entity declaration:
<!ENTITY % myParameterEntity “myElement | myElement2 | myElement3” >
Notice that there is nothing else on either side of the percent sign. When a parameter entity is referenced, you simply place the percent sign next to the entity that is being referenced followed by a semicolon:
<!ELEMENT AN ELEMENT
(%myParameterEntity; |anotherElement)*>
The xml declaration is part of the document prolog, as you will discover later, and not part of the document instance (the main body of the document that holds the data you are working with). It has no bearing on the ordering or nesting of elements and is, in fact. not an element itself. Therefore, it is not subject to the rule that dictates that a root element must contain all other elements. This is not an exception to any rules; it is part of the rules. Because an xml declaration does not qualify as an element, it is not subject to the rules to which elements must adhere. It is also not a processing instruction, although it looks like one. A processing instruction hands off instructions to another application. An xml declaration does not do that.
Parameter Entities Code
<?xml version = "1.0" standalone="no"?> <!DOCTYPE DOCUMENT SYSTEM "order.dtd"> <DOCUMENT> <CUSTOMER> <NAME> <LAST_NAME>Smith</LAST_NAME> <FIRST_NAME>Sam</FIRST_NAME> </NAME> <DATE>October 15, 2001</DATE> <ORDERS> <ITEM> <PRODUCT>Tomatoes</PRODUCT> <NUMBER>8</NUMBER> <PRICE>$1.25</PRICE> </ITEM> <ITEM> <PRODUCT>Oranges</PRODUCT> <NUMBER>24</NUMBER> <PRICE>$4.98</PRICE> </ITEM> . . . <ITEM> <PRODUCT>Asparagus</PRODUCT> <NUMBER>12</NUMBER> <PRICE>$2.95</PRICE> </ITEM> <ITEM> <PRODUCT>Lettuce</PRODUCT> <NUMBER>6</NUMBER> <PRICE>$11.50</PRICE> </ITEM> </ORDERS> </CUSTOMER> </DOCUMENT>