Chapter 4. XML Document Type Definitions
Document Type Definitions (DTDs) are important in data exchange. Parties exchanging data must agree on a format, and a DTD allows the specification of that format.
DTDs are used to specify the allowed syntax of an XML application [XML], including the values of entities and special properties of attributes—for example, that an attribute is a unique element identifier (ID). Familiarity with DTDs is useful because they are a fundamental part of XML parsing. In this book, we use DTDs to specify the syntax for XML signatures and some other XML security structures.
Recently, the W3C devised a new method of syntax specification, called XML Schema [Schema], which is described in detail in Chapter 5. Schemas are used in the XML Security standards and this book as the more
If you are already familiar with DTDs, you can skip the rest of this chapter.
4.1 Introduction to DTDs
An XML document consists of a prolog and a body. The document prolog contains the XML declaration and the document type declaration for that document, both of which are optional. The document type declaration specifies the root element of the document, and it can specify the DTD. The document body contains the actual
The markup in an XML document describes the document's storage and logical structure and
The XML Recommendation [XML] defines the XML document type declaration as containing or pointing to markup declarations that provide a grammar for a class of documents. A markup declaration serves one of four purposes:
This grammar is known as a Document Type Definition. A DTD defines the
The document type declaration can point to an external subset (a special kind of external entity) containing markup declarations, it can contain the markup declarations directly in an internal subset, or it can do both. The DTD for a document consists of both
Because you can define a DTD within a document or reference and access it externally, a single DTD can apply to one document or to many documents. External DTDs, by convention, appear in an ASCII text file with the extension .dtd. For example:
Elements and attribute declarations form a framework against which a parser can test documents to see whether they meet the format described by the DTD. Declarations communicate information to the parser about document content, such as the following:
Although XML documents are not required to have a DTD, a large percentage of the XML specification [XML] deals with various sorts of declarations that are allowed in DTDs.
All XML documents must be well formed, as described in Chapter 3. A validating XML processor can use the DTD to validate a document—that is, not only to require it to be well