- Introduction
- Internal Versus External Entities
- General and Parameter Entities
- Parsed Versus Unparsed Entities
General and Parameter Entities
The second syntax criterion (where the entity will be used) affects both the entity declaration and reference. The entity shown in Listing 1 is called a general entity, because it's referenced within the body of the document. If the entity is to be referenced within the DTD, it's called a parameter entity. For parameter entities, it's necessary to add a % character to the <!ENTITY> markup:
<!ENTITY % base_att_list 'xml:lang CDATA "en-us"'> <!ELEMENT message (#PCDATA)> <!ATTLIST message %base_att_list;>
The benefit of using a parameter entity to declare attributes like this is that if multiple tags have a common base set of attributes, the base set can be changed in a single location.
NOTE
The rules about where and how parameter entities can be declared and used are arguably the most complex part of the XML 1.0 specification. For instance, the preceding XML snippet is perfectly valid if it's included in the external DTD subset (stored in a file separate from the main document). It's invalid, however, if it's included directly in the internal subset (the portion of the <!DOCTYPE> declaration between the [ and ] characters). If you plan to rely heavily on parameter entities in your documents, consult a comprehensive XML reference.