The DOCTYPE Declaration

A document type declaration contains internal markup declarations or points to external markup declarations that provide a grammar for validating a given document or class of documents.

Productions

[28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
[28a] DeclSep ::= PEReference | S
[28b] intSubset ::= (markupdecl | DeclSep)*
[29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI |
Comment

Examples

<!DOCTYPE message SYSTEM "myMessage.dtd" >

<!DOCTYPE message SYSTEM "http://www.example.com/DTD/myMessage.dtd" >

<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3.org/
TR/xhtml1/DTD/xhtml1-strict.dtd" >

<!DOCTYPE message [
  <!ELEMENT message (#PCDATA) >
  <!ATTLIST message date CDATA #REQUIRED >
]>

<!DOCTYPE message SYSTEM "myMessage.dtd" [
  <!ATTLIST message info CDATA #IMPLIED >
]>

Description

A document type or DOCTYPE declaration provides information to a validating XML parser about how to validate an XML document. The DOCTYPE keyword appears first; then the document, or root, element of the document being validated is identified, followed by either a SYSTEM or PUBLIC identifier.

SYSTEM indicates that the DTD will be found as indicated in the filename or URI that follows (also called a system literal; for example, "myMessage.dtd" or "http://www.example.com/DTD/myMessage.dtd“).

PUBLIC hints that the DTD is standard, well known, and widely available—although technically, it just means that a ...

Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.