XML

Entities and Other Components

In tutorial 4, we examined the two principal components of a document type definition (DTD): elements and attributes. In this tutorial, we will look at some additional components that can be added to the DTD. The focus of this tutorial will be entities, which are used to represent text that can be part of either the DTD or the XML document.

You can use a single entity to represent a lengthy declaration and then use the entity in the DTD. You can also use entities to make one common file that contains a set of standard declarations that can be shared by many DTDs.

Entities are like macros in the C programming language in that they allow you to associate a string of characters with a name. This name can then be used in either the DTD or the XML document; the XML parser will replace the name with the string of characters. All entities consist of three parts: the word ENTITY, the name of the entity (called the literal entity value), and the replacement text-that is, the string of characters that the literal entity value will be replaced with. All entities are declared in either an internal or an external DTD.