Parameter vs General Entities in XML DTD Parsing

In XML Document Type Definitions (DTDs), entities function as variables or macros to facilitate reusability and maintainability. The fundamental difference between a general entity and a parameter entity lies in their scope of use and syntax: general entities are referenced within the XML document content itself, while parameter entities are restricted solely to the DTD for defining and modularizing schema structures.

General Entities

General entities are designed to insert text, special characters, or external content into the body of an XML document. They can also appear within the replacement text of other entities in the DTD.

Parameter Entities

Parameter entities are used exclusively within the DTD to create reusable components for markup declarations, such as element lists, attribute definitions, and conditional sections. They cannot be expanded within the XML document instance.

Key Differences at a Glance

Feature General Entity Parameter Entity
Primary Purpose Content substitution in XML documents Schema/markup modularity in DTDs
Reference Location XML document body (and DTD values) Exclusively within DTD declarations
Reference Delimiters &name; %name;
Declaration Keyword <!ENTITY name "value"> <!ENTITY % name "value">
Parser Handling Expanded when parsing XML elements Expanded when compiling the DTD