Previous Table of Contents Next


Chapter 14
Following Good SGML Practice

You know how to do some SGML now, but there is much more to SGML than just writing a DTD or marking up a document instance. There is the issue of good judgment when it comes to design. Design issues quickly become maintenance issues. If you inherit someone’s DTD that was not designed well, then you have a maintenance problem.

In this chapter, you learn:

  How to choose whether to use an element or an attribute
  How to handle inclusions and exclusions
  What to do about mixed content models
  How to avoid ambiguous content models
  How flexible a DTD should be
  How to avoid other problems

These questions are important because SGML does not always alert you when you do something wrong—at least not right away. It lets you get away with many mistakes. Parsing errors mainly deal with syntax, not overall design. In this chapter, you learn how to avoid the major pitfalls.

Choosing Elements or Attributes

Deciding whether to make a tag an element or attribute is difficult when you can’t decide what the object you’re working on really does and how it does it. Suppose, for example, that you want to describe where a graphic object is located. Call it fileloc for file location. The object is visible in the document. You could tag it every time it appears. Do you call it an element or an attribute?


Note:  
When you think you understand the difference between elements and attributes, look at the structural objects in a magazine article. Pretend that you’re the production editor and the SGML analyst. See whether you can figure out what the elements are for the document—the article—and its attributes. Whether you are right or wrong is not so important. The exercise in thinking about elements and attributes will be worth far more to you in the long run than getting it right.

The following note about elements being the object and attributes defining an aspect of the object helps, but sometimes there’s more to it. Remember when you were in a class, and there was someone who just did not get it? Or maybe the someone was you when your dad was explaining something about cars or refrigerators. You felt like the odd person out. Everyone else in the class seemed to understand. What everyone else had was the “feel” of the subject matter. SGML is like that when it comes to attributes and elements.


Note:  
The element is the structural object, and the attribute defines an aspect of it. If the element were <GRAPHIC>, the attribute could be location and the values could be local and remote. If the element were <ATTENDANCE>, the attribute could be status and the values could be present and absent.

Types of Attributes

The question becomes, “Is it an attribute or not?” It is probably an element if it is not an attribute. The other choice is an entity, which is discussed in Chapter 10. There are four main types of attributes:

  Attributes that define aspects about the element; if the element is block, its attributes might be size, color, weight, and shape
  Attributes that contain formatting information or other information that affects the appearance of the element; if the element is a paragraph, it might be indented, justified, columns, and so on
  Attributes that locate an internal object, such as a cross reference, a footnote, or a graphics file name
  Attributes that locate an external object, such as a link to a different document or another file on a related network


• See “Entities: Their Use and The ENTITY Markup Declaration,” p. 184

There are other types of attributes; not all attributes fall into these categories. You can call your objects whatever you want, as long as you follow SGML syntax.


Previous Table of Contents Next