DTDs are introduced into XML documents using the document type declaration (i.e.,
DOCTYPE). A document type declaration is placed in the XML document's prolog and begins with <!DOCTYPE and ends with >.
The document type declaration can point to declarations that are outside the XML document (called the external subset) or can contain the
declaration inside the document (called internal subset). For example, an internal subset
might look like
The first myMessage is the name of the document type declaration. Anything inside
the square brackets ([]) constitutes the internal subset. As we will see momentarily, ELEMENT
and #PCDATA are used in element declarations.
External subsets physically exist in a different file that typically ends with the.dtd extension,
although this file extension is not required. External subsets are specified using either keyword SYSTEM or PUBLIC.
For example, the DOCTYPE external subset might look like
<!DOCTYPE myMessage SYSTEM "myDTD.dtd">
which points to the myDTD.dtd document. Using the PUBLIC keyword indicates that the DTD is widely used
(i.e., the DTD for HTML documents). The DTD may be made available
in well-known locations for more efficient downloading.
The DOCTYPE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
uses the PUBLIC keyword to reference the well-known DTD for HTML version 4.01.
XML parsers that do not have a local copy of the DTD may use the URL provided to download the DTD to perform validation.
Both the internal and external subset may be specified at the same time. For example,
the DOCTYPE