Previous Table of Contents Next


When Attributes Aren’t Enough. Some types of content can’t be described by elements and attributes alone. There are a number of times when you want to introduce something that is unique—say a special character, like a circumflex (^), for example—and you don’t want to associate it with either an element or an attribute. That’s when you want to use what’s called an entity.

An entity is a markup component of a document, something like an element. But entities are more like superelements because you can do more with them than you can with elements. Entities are multipurpose moving boxes that not only can move your document’s content, but can also provide for transport shortcuts along the way. They help the SGML processing system do its job smarter. If elements and entities were chess pieces, elements would be like bishops or castles that move many spaces either at right angles or diagonally, but not both. Entities would be like the queen who can move in any direction, except you can use as many of them as you need. Entities are no less valuable to your document than the queen is to a chess player. They are extremely flexible and will save the day when nothing else can.

Entities

There are at least five cases when you need to use entities in your SGML document. For each of these five cases, elements and attributes are not enough:

  You need to use some special character, like a dollar sign ($), that isn’t in your character set. (Since SGML was developed long ago on ASCII terminals when only alpha-numeric ASCII characters could support document interchangeability, any other characters are considered “special characters.”)
  You need to include information from some external file in an SGML document, such as a spreadsheet that’s updated everyday.
  You want to use a shorthand notation in the authoring process without the shorthand being visible to the document user. For example, if you want to author SGML legal documents, you can substitute “POFP” for “party of the first part,” and whenever you type the abbreviation, the entire text appears in the SGML document.
  You want to use parameter entities—meaning a “variable” within your DTD. You learn more about these in the next section.

Two Types of Entities: General (&) and Parameter (%). When entities appear in documents, they look like these examples: &CALS;, %ememo;, %ISOpub;. Entities either use & or % in front to identify themselves. General entities always use & and parameter entities always use % in documents. Furthermore, there are internal and external entities for both general and parameter entities. Both entities require a close delimiter, or something that turns it off. The close delimiter is a semicolon.

General entities are substitutes for characters or strings. Use them when you want to denote a special symbol or string of characters. For example:

  &CALS;  Computer Aided Logistics Support
  }  ASCII value for character 125 of the set: "}"

Parameter entities are substitutes for larger objects like document types or character sets in DTDs. Use them when you want to refer to public entities or make model group references. For example:

  %ememo; Special model of document good for this one instance only
  %ISO123; ASCII character numbered 123 in the current character set

There are two types of both general and parameter entities. Both types of entities can be grouped further by internal and external entities. See figure 3.4 for an illustration of these groupings.


Fig. 3.4  Entities fall into two broad categories, general and parameter entities.

Each of the two categories in figure 3.4 falls into internal and external entities. There are internal and external parameter entities, as well as internal and external general entities. Parameter entities usually show up in DTDs, while general entities can show up in documents or in DTDs.


Previous Table of Contents Next