Previous Table of Contents Next


In the previous examination of elements and element tag minimization, you looked at a declaration for the element graphic. If you take another look at it with its corresponding attribute list declaration, it might make a little more sense:

    <!ELEMENT  graphic   - o    EMPTY >
    <!ATTLIST  graphic        filename CDATA #REQUIRED
                              artno    CDATA #IMPLIED>

In this example, you have the element graphic, with no content or end tag. You now have a corresponding attribute list that defines the attributes filename and artno, both of which consist of character data.

Notice that the attribute filename is required. Through this use of SGML declarations, you are able to put in a place holder in the document instance that points to a related illustration. The element graphic has no content, but it must contain an attribute value for filename that points to the file containing the illustration.

On occasion, it might be useful to navigate between specific occurrences of elements in the document instance. When this situation occurs, you can use the attribute types of ID and IDREF.

To do this, define an attribute using the keyword ID. You must ensure that this keyword value is unique. (This attribute can be either #REQUIRED or #IMPLIED. If it’s #IMPLIED, the processing program must supply a unique value.)

    <!ELEMENT sect     - - (para)+>
    <!ATTLIST sect         id      ID #REQUIRED>

Now that you have a specific address within your SGML document instance (consisting of an element with a unique ID), it’s relatively simple to cross-reference (or hyperlink) to it. Through the use of the IDREF (or ID reference), you can refer back to your original element.

    <!ELEMENT xref     - - (misc)+>
    <!ATTLIST xref         findit  IDREF #REQUIRED>


Note:  
Refer to Chapter 25 for more detailed information on document links.

Entities: Their Use and the ENTITY Markup Declaration

Within SGML, entities provide a powerful and compact shorthand mechanism for using symbolic notation. With them, you can point to a specific character string that may be difficult or laborious to include otherwise. They perform their work via the parser, as it resolves the symbolic references during the parsing process by performing string replacement.

To use entities, two things must be done. First, you must define the entity with an ENTITY declaration, and then you must call the entity via an entity reference.

Entity references can be particularly useful for the following purposes:

  Indicating special characters not easily accessible from a keyboard (such as scientific symbols or foreign language characters)
  Substitution of long character strings via a shorthand notation
  Inclusion of a reusable document content model fragment (throughout a DTD and across DTDs)
  Machine-specific processing commands
  As a pointer to a specific file on your computer system

There are two basic types of entities: general entities and parameter entities. General entities can be used in a number of circumstances, while parameter entities can only be used within specific markup declarations (in DTDs).

Either type of entity can be internal or external. Internal entities reference objects defined within the DTD, while external entities point to an object beyond the boundaries of the DTD.


• See “Two types of Entities: General (&) and Parameter (%),” and “Internal and External General Entities,” pp. 58-59

The ENTITY Declaration. The ENTITY declaration is a relatively simple one. (By now, you’re probably rather familiar with the general syntax of SGML declarations.) The following illustrates the components and layout of an entity declaration:

Notice that the entity declaration has the usual markup delimiter open and close (MDO and MDC) and the keyword that identifies it as an entity. The content between the literal string delimiters is the actual entity value.

General Entities. Through the use of general entities, you can define special characters and symbols not easily typed on a standard keyboard and call them up via entity references.

Parameter Entities. Within a DTD, parameter entities can be used to access content model fragments from a single location. Through this mechanism, you can ensure that you’re using a common, consistent set of content model “chunks.” Parameter entities can reference fragments that are internal or external to the DTD.

Externally referenced entities can be either local to a specific installation, or they can be public (or published) standard reference entities.

The declaration for a parameter entity varies slightly from the general entity declaration noted previously:

    <!ENTITY  %    NAME   entity-value    >

Notice the percent sign (%), which indicates a parameter entity. Also note that the entity value may contain a literal (or textual) content, a reference to an external entity specification, or a specialized processing instruction.


Previous Table of Contents Next