Using XML Entities
When you're authoring complex documents or creating multiple related documents, certain content fragments tend to be repeated over and over again. For example, a series of XHTML web pages might share a set of common footer tags. Entities are provided as a primitive macro facility to allow commonly repeated sequences of document content and even DTD declarations to be defined and referenced by name.
Listing 1 shows a simple entity declaration and reference.
Listing 1A Simple Entity Example
<!DOCTYPE message [ <!ELEMENT message (#PCDATA)> <!ENTITY my_message "Hello, world." > ]> <message>&my_message;</message>
First, the entity is declared using the <!ENTITY> markup, and then the associated text ("Hello, world.") is included in the target document, using a normal entity reference (&my_message;). The actual syntax of entity declarations and references changes based on the following:
Where the replacement text comes from (an inline string or an external file)
Where the entity will be referenced (within the DTD or the document)
Whether the resulting replacement text will be read by the parser