A document type declaration is an optional declaration that can contain markup declarations (see Markup declarations) to define constraints on the logical structure of a document or class of documents, and to provide support for the use of predefined storage units (entity references) within the document. The document type declaration identifies the root element of the document and may contain additional declarations. All XML documents must have a single root element that contains all of the content of the document. Additional declarations may come from an external definition (see Document type definition (DTD)) or be included directly in the document, or both.
If present, the document type declaration must appear immediately after optional processing instructions and comments in the document. XML content can be processed without a declaration. However, there are instances where the declaration is required:
▪In authoring environments: Most authoring environments need to read and process document type declarations in order to understand and enforce the content models of the document.
▪When default attribute values are used: If an XML document relies on default attribute values, at least part of the declaration must be processed in order to obtain the correct default values.
▪When white space handling is an issue: White space is significant in mixed content and is insignificant in element content. The rule for XML processors is that in the absence of a declaration that identifies the content model of an element, all white space is significant. If you need precise control over white space handling, you must provide a declaration.
In order to determine if a document is valid, the XML processor must read the entire document type declaration (both internal and external). But for some applications, validity may not be required, and it may be sufficient for the processor to read only the internal declaration. A value of internal indicates that only the internal declarations need be processed. A value of all indicates that both the internal and external declarations must be processed. A value of none indicates that the document can be processed without reading either declarations.
If both is specified, the XML processor reads the internal declaration before the external declaration. This is important if the declarations contain duplicate ATTLIST or ENTITY declarations. In XML, the first declaration takes precedence. Duplicate ELEMENT declarations are not allowed.
Markup declarations
A markup declaration is one of a class of declarations that can appear only within the document type declaration, and that define the grammar for a class of XML documents. There are four types of markup declarations: element type declaration, attribute-list declaration, entity declaration, and notation declaration. These declarations may be contained in whole or in part in general and parameter entities (see General and parameter entities).