Attributes Entitites   «Prev  Next»

Lesson 4Defining entities
Objective Define entities in a DTD.

Defining XML Entities

In HTML, you can include special characters through the use of pre-defined entities such as these: <
"
©
These entities represent predefined characters that are not keyboard characters or that might be interpreted incorrectly by the browser. For example, &lt; represents the "less than" left-angle bracket character (<). Entities are defined in HTML to help define certain characters that might otherwise be interpreted differently.

Built-in entities


In XML, there are five built-in entities that you need not define but can readily use. These are:
&lt;
&gt;
&quot;
&apos;
&amp;

Declaring general entities


A general entity is defined in a DTD and referenced in the XML document. In a DTD, you can define your own entities in addition to five listed above. You can also define multiple characters.
If you have ever performed a "mail merge," you are familiar with using replaceable fields to represent actual text. Think of an entity as a replaceable field representing some other text. The beauty of using entities is that you can define them once in a DTD and then use them throughout a range of documents.
Declare an entity using the following syntax:
< !ENTITY entityName "character string represented"> 

If in your DTD you declared the following entity:
< !ENTITY prodname "ACME Calendar"> 
you could use the following in your XML file: Thank you for choosing &prodname; as your primary scheduling program.
When rendered by a user agent, the actual text would then read as follows:
Thank you for choosing ACME Calendar as your primary scheduling program.
The next lesson shows you how to create parameter entities to use within a DTD.