Skip to main content

XML DTD Entities

Entities are used to define shortcuts to special characters.

Entities can be declared internal or external.

note

An entity has three parts:

  1. An ampersand (&)
  2. An entity name
  3. A semicolon (;)

Example of Internal Entity Declaration

Syntax

<!ENTITY entity-name "entity-value">

Example

DTD
<!ENTITY writer "Tom Nolan">  
<!ENTITY copyright "Copyright TutorialReference.">
XML
<author>&writer;&copyright;</author>

Example of External Entity Declaration

Syntax

<!ENTITY entity-name SYSTEM "URI">
or
<!ENTITY entity-name SYSTEM "URL">

Example

DTD
<!ENTITY writer SYSTEM "https://tutorialreference.com/entities.dtd">  
<!ENTITY copyright SYSTEM "https://tutorialreference.com/entities.dtd">
XML
<author>&writer;&copyright;</author>