Export (0) Print
Expand All
1 out of 5 rated this helpful - Rate this topic

DOCTYPE Declaration [XML Standards]

The DOCTYPE declaration provides a space for a document to identify its root element and document type definition (DTD) by reference to an external file, through direct declarations, or both.

A DOCTYPE declaration can contain:

  • The name of the document or root element.

    This is required if the DOCTYPE declaration is used.

  • System and public identifiers for the DTD that can be used to validate the document structure.

    If a public identifier is used, a system identifier must also be present.

  • An internal subset of DTD declarations.

    The internal subset appears between square brackets ([ ]).

A DOCTYPE declaration is mandatory if the document is to be processed in a validating environment. To be valid, the DOCTYPE declaration must identify a DTD that corresponds to the document structure of the document. Nonvalidating parsers will accept documents without DOCTYPE declarations.

The simplest DOCTYPE declaration identifies only the root element of the document.

<!DOCTYPE rootElement>

More often, documents that use the DOCTYPE declaration reference an external document containing the declarations that make up the DTD. The following can be used to identify the external DTD.

<!DOCTYPE rootElement SYSTEM "URIreference">

The URIreference points to a file containing the declarations.

<!DOCTYPE rootElement PUBLIC "PublicIdentifier" "URIreference">

The PublicIdentifier provides a separate identifier that some XML parsers can use to reference the DTD in place of the URIreference. This is useful if the parser is used on a system without a network connection or where that connection would slow down processing significantly.

DOCTYPE declarations can also include declarations directly, in what is referred to as the internal subset. If a DOCTYPE declaration includes the entire DTD directly, without reference to external files, it uses the following syntax.

<!DOCTYPE rootElement [
declarations
]>

If the DOCTYPE declaration includes declarations that are to be combined with external files or the external subset, it uses the following syntax.

<!DOCTYPE rootElement SYSTEM "URIreference"[
declarations
]>

or

<!DOCTYPE rootElement PUBLIC "PublicIdentifier" "URIreference"[
declarations
]>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.