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 marked-up document.

The markup in an XML document describes the document's storage and logical structure and associates attributes and their values with its logical structures, as described in Chapter 3. XML DTDs provide a vocabulary and syntax for describing a document's structure. The XML Recommendation provides document type declarations to define constraints on the logical structure and to support the use of predefined storage units.

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:

  • It is an element type declaration (see Section 4.3).

  • It is an attribute-list declaration (see Section 4.4).

  • It is an entity declaration (see Section 4.5).

  • It is a notation declaration (see Section 4.6).

This grammar is known as a Document Type Definition. A DTD defines the allowable building blocks of an XML document; that is, it defines the document structure with a list of permissible elements, attributes, nestings, and so on.

graphics/note.gif

To make matters confusing, you could potentially use the abbreviation "DTD" for two different terms. The document type declaration includes everything between the string "<!DOCTYPE" and the matching ">". It can contain the Document Type Definition (DTD), or it can contain part of and point to the DTD. When people talk about the document type declaration, they usually say "doctype declaration" for short [XML A].


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 subsets taken together.

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:

 mydtd.dtd 

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:

  • The allowable sequence and nesting of tags

  • Attribute values, including their types and defaults

  • Names of referenced external files, whether or not they contain XML, and the format of non-XML data that might be referenced

  • Entities that might be present

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 formed but also to determine whether the document conforms to the definitions. If the document can be parsed successfully with a validating parser and its DTD, the document is valid. To be valid, a document's DTD must specify all of its structure. XML documents read by a nonvalidating parser do not have to be valid.



Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net