Previous Table of Contents Next


What Are the Components of DTDs?

The building blocks of DTDs are much the same as those of SGML documents. It’s just that they’re more involved and thorough in DTDs. Just as documents have elements, attributes, and entities, so do DTDs, but they look different and are more specific. That’s because every element, attribute, and entity that is mentioned in a document must be definedin a DTD for that document type. How those definitions appear in the DTD is called DTD syntax.


NOTE:  
Because the DTD must define all the elements, attributes, and entities found in all documents of its document type, it must follow a specific format for doing so. While there is a fair amount of flexibility one can have with DTDs, syntax is not negotiable. If you fail to follow DTD syntax, your documents will not parse.


• See “SGML Declaration Syntax (or “What Are All Those Angle Brackets Anyway?”),” p. 172

DTDs and Declarations for Elements, Attributes, and Entities

DTDs have a lot to do. When it comes to declarations, DTDs must define all the elements, attributes, and entities of the document type and describe everything possible about that definition. And it must all happen within a very short space. Specifically, here’s the minimum of what a DTD must accomplish in its declarations:

  Provide the names of all elements used in a document type.
  Specify the type of content of each element, including which other elements may compose each element.
  Specify which order each element must appear in.
  Define how often an element may appear in a document.
  Decide whether shorthand can be used with the tag delimiters (this is called minimization and mainly applies to the manual tagging process, which may not be applicable to your situation).


• See “Tag Minimization,” p. 186
  Specify whether short references (shorthand references to an entity within the text content of a document) can be used. (This is primarily for the manual tagging process and may not apply to your situation).


• See “Tagging Shorthand,” p. 289
  Define which attributes for each element exist.
  Define the default values for each attribute.
  Define any entities that may exist in the document type.
  Declare the document type.
  Declare any comments regarding any of the above or any general comments about the document type of which anyone else reading the DTD should be made aware.

Components of a Declaration in a DTD

Declarations contain groups, connectors and/or tokens, and names. An example of an element declaration with its attribute declaration appears below:

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

This declaration declares table as an element and says it must be composed of title, followed by either one or more instances of tgroup and possibly tnote, or one instance of graphic. That is, you get title followed by tgroup possibly followed by tnote; or you get title followed by graphic. The declaration further lists two attributes of table: one is the entity stdatt and the other is the element label. Label is composed of CDATA (character data), and the attribute default is determined by the processing system.

SGML knows what to expect after it sees certain keywords and symbols. Everything means something in a DTD. Let’s just start with the table element declaration (see table 3.3).

Table 3.3 Parts of the Element Declaration

Component What It Means

<!ELEMENT Tells SGML you’re declaring an element
table The name of the element
- - Says no minimization of either start tag or end tag delimiter
(title, ((tgroup+, tnote?)|graphic)) This is the whole name group
(title, First component of table
((tgroup+, tnote?)|graphic)) Second component of table (this component uses one of two possible subcomponents)
(tgroup+, tnote?) First possible subcomponent
graphic Second possible subcomponent
> End declaration delimiter

The ,, (, +, |, and ? are called connectors and occurrence indicators. They tell the parser when and how often to expect components specified in a declaration. These occurrence indicators are used in the groups of a DTD.


Previous Table of Contents Next