XML Parameter Entities

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:

 (%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.

Previous: XML External Entities
Next: XML Proper nesting of elements

Follow us on Facebook and Twitter for latest update.