Search This Blog

Tuesday, November 13, 2018

How to declare an entity in XML DTD

Entities are variables used to define shortcuts to standard text or special characters.
  • Entity references are references to entities
  • Entities can be declared internal or external
Declare An Internal Entity

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

DTD Example:
<!ENTITY author "i88.ca"><!ENTITY copyright "Copyright IT.I88.CA.">
XML example:
<sponsor>&author;&copyright;</sponsor>
Note: An entity has three parts: an ampersand (&), an entity name, and a semicolon (;).

An External Entity Declaration
Syntax
<!ENTITY entity-name SYSTEM "URI/URL">
Example

DTD Example:
<!ENTITY author SYSTEM "http://it.i88.ca/entities.dtd">
<!ENTITY copyright SYSTEM "http://
it.i88.ca/entities.dtd">
XML example:
<sponsor>&author;&copyright;</sponsor>