Previous | Table of Contents | Next |
The building blocks of DTDs are much the same as those of SGML documents. Its just that theyre 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. Thats 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 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, heres the minimum of what a DTD must accomplish in its declarations:
See Tag Minimization, p. 186
See Tagging Shorthand, p. 289
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. Lets just start with the table element declaration (see table 3.3).
Component | What It Means |
---|---|
<!ELEMENT | Tells SGML youre 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 |