Elements and Attributes

SGML/XML markup consists primarily of elements, attributes, and entities. Elements are the terms we have been speaking about most, like sect1, that describe a document's content and structure. Most elements are represented by pairs of tags and mark the start and end of the construct they surround—for example, the SGML source for this particular paragraph begins with a para tag and ends with a para tag. Some elements are “empty” (such as DocBook's cross-reference element, xref) and require no end tag.[1]

Elements can, but don't necessarily, include one or more attributes, which are additional terms that extend the function or refine the content of a given element. For instance, in DocBook a sect1 start tag can contain an identifier—an id attribute—that will ultimately allow the writer to cross-reference it or enable a reader to retrieve it. End tags cannot contain attributes. A sect1 element with an id attribute looks like this:

<sect1 id="idvalue">

In SGML, the catalog of attributes that can occur on an element is predefined. You cannot add arbitrary attribute names to an element. Similarly, the values allowed for each attribute are predefined. In XML, the use of namespaces may allow you to add additional attributes to an element, but as of this writing, there's no way to perform validation on those attributes.

The id attribute is one half of a cross reference. An idref attribute on another element, for example xref linkend=”idvalue” , provides the other half. These attributes provide whatever application might process the SGML source with the data needed either to make a hypertext link or to substitute a named and/or numbered cross reference in place of the xref. Another use for attributes is to specify subclasses of certain elements. For instance, you can subdivide DocBook's systemitem into URLs and email addresses by making the content of the role attribute the distinction between them, as in systemitem role="URL" versus systemitem role="emailaddr".

Notes

[1]

In XML, this is written as <xref/>, as we'll see in the section the Section called Typing an SGML Document in Chapter 2.