A document type definition is a collection of ELEMENT , ATTLIST , ENTITY , and NOTATION declarations that describes a class of valid documents. A document type declaration is placed in the prolog of an XML document. It contains and/or points to the document's document type definition . The document type definition and the document type declaration are closely related , but they are not the same thing. The acronym DTD refers exclusively to the document type definition, never to the document type declaration. The shorthand form DOCTYPE refers exclusively to the document type declaration, never to the document type definition.
For example, this is a document type declaration:
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "docbook/docbookx.dtd" >
It points to the DTD with the public identifier -//OASIS//DTD DocBook XML V4.1.2//EN found at the relative URL docbook/docbookx.dtd.
The following is also a document type declaration.
<!DOCTYPE book SYSTEM "http://www.example.com/docbookx.dtd">
It points to the DTD at the absolute URL http://www.example.com/docbookx.dtd.
Here is a document type declaration that completely contains the DTD between the square brackets that delimit the internal DTD subset.
<!DOCTYPE book [ <!ELEMENT book (title, chapter+)> <!ELEMENT chapter (title, paragraph+)> <!ELEMENT title (#PCDATA)> <!ELEMENT paragraph (#PCDATA)> ]>
Finally, the next document type declaration both points to an external DTD and contains an internal DTD subset. The full DTD is formed by combining the declarations in the external DTD subset with those in the internal DTD subset.
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "docbook/docbookx.dtd" [ <! add XIncludes > <!ENTITY % local.para.char.mix " xinclude:include"> <!ELEMENT xinclude:include EMPTY> <!ATTLIST xinclude:include xmlns:xinclude CDATA #FIXED "http://www.w3.org/2001/XInclude" href CDATA #REQUIRED parse (text xml) "xml" > ]>
Whether the DTD is internal, external, or both, it is never the same thing as the document type declaration. The document type declaration specifies the root element. The DTD does not. The DTD specifies the content models and attribute lists of the elements. The document type declaration does not. Most APIs routinely expose the contents of the document type declaration but not those of the document type definition.