Name

Parameter Entity Declarations

Synopsis

                        <!ENTITY
                         % 
                        name 
                        "
                        Replacement text
                        .">
                        <!ENTITY
                         % 
                        name 
                        SYSTEM "
                        system-literal
                        ">
                        <!ENTITY
                         % 
                        name 
                        PUBLIC "
                        pubid-literal
                        " "
                        system-literal
                        ">

Parameter entities are declared within the document’s DTD and must be declared before they are used. The declaration provides two key pieces of information:

  • The name of the entity, which is used when it is referenced

  • The replacement text, either directly or indirectly through a link to an external entity

Be aware that an XML parser performs some preprocessing on the replacement text before it is used in an entity reference. Most importantly, parameter entity references in the replacement text are recursively expanded before the final version of the replacement text is stored. Character references are also replaced immediately with the specified character. This replacement can lead to unexpected side effects, particularly when constructing parameter entities that declare other parameter entities. For full disclosure of how entity replacement is implemented by an XML parser and what kinds of unexpected side effects can occur, see Appendix D of the XML 1.0 specification. The specification is available on the World Wide Web Consortium web site (http://www.w3.org/TR/REC-xml#sec-entexpand).

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.