Previous Table of Contents Next


Tags and Tag Minimization with Omittag

The Omittag feature of SGML is an optional function that allows you to leave out start and stop tags that have been designated as optional in your DTD. This can be useful in systems where the SGML markup is manually inserted in a document.

To use Omittag, this feature must be designated in the SGML declaration as a permitted feature and it must be specifically allowed in the element declaration where you want to use it.

In the element declaration that follows, no tags can be omitted.

    <!ELEMENT subject  - - (#PCDATA)>

If you want to allow the omission of the end tag on this element, you would define the element a little differently:

    <!ELEMENT subject  - O (#PCDATA)>

Note that the second hyphen (-), has been replaced with an uppercase letter “O.” This indicates that the end tag can be omitted. (Similarly, if you want to allow omission of the start tag, you would replace the first “-” with an “O.”)

In general, tags can be omitted only when their omission does not create ambiguity in the document instance. For example, take a look at the following DTD fragment:

    <!ELEMENT document  - -  ((section),para?)     >
    <!ELEMENT section   - O  (para+)               >
    <!ELEMENT para      - -  (#PCDATA)             >

This example is illegal. You cannot allow the omission of the end tag for the element section. This is because you would not be able to tell whether the last occurrence of the element para occurred within the section element or just after it. (It is ambiguous.)


Tip:  
There are several other instances where start tags cannot be omitted: the element has a required attribute, the element begins with a SHORT REF delimiter, the element has declared content (CDATA, RCDATA, EMPTY).

In the first scenario, omitting the tag would leave no place for the attribute. In the second, the short reference mapping would probably become misleading. In the third, the parser would be unable to understand when to stop parsing content.


Not all SGML processing systems support tag minimization. As a result, all markup tags should be restored if you are going to send your SGML to a recipient who might not be able to support it.

Some Practical Examples

To follow up on the subjects covered in this chapter, let’s take a look at a DTD. Let’s look again at the DTD that was introduced in Chapter 5, “Two Scenarios” (see fig. 10.1).


Fig. 10.1  This sample DTD contains a number of declarations including those for doctype, elements, comments, attributes, and entities.

As you look at this DTD, notice how the various components that you have examined in this chapter are used. For example, the entity parael (or paragraph element) is defined early in the DTD, before it is referenced.

The declaration for the element blist specifically excludes the element nlist (indicating that a bulleted list cannot include a numbered list within it).

Look at the element graphic. Notice that it is empty, and that its end tag can be omitted. In this situation, the element is used solely as a placeholder for an external graphics file.

Finally, take a look at the regular expressions used in this DTD. (For example, you’ll notice that the element item can contain one or more of any of the following elements: para, blist, nlist, or graphic.)

From Here…

This chapter examined SGML declarations and syntax, paying particular attention to the usage of comments, elements, attributes, and entities. This examination also included a look at the regular expression notation and the types of declared content used in SGML.

For more information, refer to the following chapters:

  Chapter 11, “Using DTD Components,” illustrates how to make reusable DTD document structures.
  Chapter 12, “Formatting the DTD for Humans,” discusses how to organize your DTDs to make them readable and understandable.
  Chapter 13, “Evaluating DTDs and Using Parsers,” looks at how to ensure that a DTD meets your needs and the use of parsers.
  Chapter 14, “Following Good SGML Practice,” provides a framework to follow for optimal SGML usage.


Previous Table of Contents Next