DTD - General vs Parameter Entities

1. Entities in DTD – General vs Parameter Entities

Introduction

Entities in DTD are placeholders or reusable pieces of text or markup. They allow you to avoid repetition, insert special characters, or modularize DTD content.

Types of Entities

  1. General Entities

  • Used inside XML documents.

  • Can represent text, symbols, or fragments of XML.

  • Declared using:

 
<!ENTITY entityName "replacementText">

Example:

 
<!ENTITY companyName "OpenAI"> <company>&companyName;</company>
  • Output: <company>OpenAI</company>

  1. Parameter Entities

  • Used inside DTDs to modularize or reuse definitions.

  • Referenced with %entityName;

 
<!ENTITY % commonAttrs "id ID #REQUIRED"> <!ATTLIST book %commonAttrs;>

Advantages

  • Reduces repetition and errors.

  • Supports modular DTD design.

  • Allows dynamic inclusion of external DTD fragments.