Previous Table of Contents Next


Note that you can include multiple elements in your inclusion notation but that only one type of regular expression sequencing (followed by OR, AND) is allowed within the inclusion.


Caution:  
Don’t use inclusions for elements that you forgot to include! They shouldn’t be used for subelements that are key structural components, but rather for those that float in document content (such as notes, keywords, and so on).

Exclusions are similar to inclusions in many ways, although your usage of them is somewhat different. Indicated in the markup declaration by a minus (–) rather than the plus sign (+) of inclusion, you commonly use them to prevent recursive nesting of an element within itself. For example, you might want to prevent the element note from occurring directly within another note, but might want to allow it to occur in a paragraph within a note.

Inclusions and exclusions can occur within the same element definition. However, according to the SGML standard, if you include and exclude the same content, the exclusion takes precedence.

Element Summary. In this chapter’s examination of elements within SGML, you looked at how they are declared and how you can define omitted tags in the element declaration. You took a brief look at your options for defining the content model of an element, showing that an element can contain other subelements or character data (or a combination of the two). You also took a look at the method for handling exceptions to the content model via inclusions and exclusions. But before you can really examine elements in their common setting (a document instance), you need to examine two additional SGML objects: attributes and entities.

Attributes: Their Use and the ATTRIBUTE Declaration

In the SGML world, you are able to use attributes when you need to specify some additional descriptive information or values that pertain to a specific element. They are particularly useful in describing values (or qualities) that apply to an element.

Attributes can be either optional or mandatory. In cases where they are omitted, the attribute declaration can specify a default value.

Attributes are particularly useful for including information that relates to external objects (such as illustrations, videos, or sound clips), indicating the security level of a document, including cross reference information to tie one element to another (for hypertext linking), and other element descriptive data.

Though they are defined separately from elements, the attribute values occur within the element tags in an SGML document instance. (You will see this when you examine an example of an SGML document instance and its corresponding DTD.)

To define attributes that correspond to one of your elements, use the Attribute List declaration. Here’s how the syntax works:

The Attribute List declaration opens with the MDO, followed by the keyword ATTLIST, or attribute list. The value indicated by NAME corresponds to the named element to which the attribute(s) apply. Following the element name is the name of the attribute, its value (or list of possible values), and either a default attribute value or a keyword. Note that in the case of the sample declaration above, you define three attributes that relate to the same element. This indicates that you can use a single attribute list declaration to define all attributes that apply to an element.

Here are some sample attribute list declarations with their corresponding element declarations:

    <!ELEMENT subject  - - (#PCDATA)>
    <!ATTLIST subject      safety (y|n) "n">

In this example, you have the element subject. It has a corresponding attribute list defined that contains one attribute, called safety. Its value can consist of either the letter y or the letter n. If no value is specified for the safety attribute, the default value is n.

    <!ELEMENT table    - - (title,((tgroup+,tnote?)|graphic))>
    <!ATTLIST table        label CDATA #IMPLIED>

Here you have the element table, with its corresponding attribute of label. label consists of character data (CDATA); as you probably recall, CDATA is a reserved word identifier that can contain any type of characters, including those that are normally interpreted as SGML instructions.

The keyword IMPLIED (indicated by the pound sign preceding it) tells you that the attribute is not required. If it is not present, the application processing the SGML document instance will select a default value.

The range of allowable attribute keyword default types (and their meanings) are shown in table 10.5.

Table 10.5 Attribute Keyword Defaults

Keyword Meaning

#REQUIRED Attribute value is required. Default value is not allowed.
#IMPLIED Attribute value is optional. If not present, value is supplied by processing application.
#CURRENT The last supplied value for this attribute becomes the default value.
#CONREF Stands for content reference. The processing application can use the value of the attribute to generate the content value.


Tip:  
#CONREF is useful in situations where you might refer to elements that may or may not be present, such as in large documents that are not always processed in their entirety. In such situations, the use of #CONREF avoids problems with unresolved references.


Previous Table of Contents Next