What is a Document Type Declaration in XML?

The most current version as of .

A Document Type Declaration is a way to link the Document Type Definition to an XML document.

To do this, we need to add a Document Type Declaration to the XML document.

This can be done either internally or externally.

Internal Document Type Declaration

<!DOCTYPE root-element [ … ]>

Where …

  • … the root-element is the name of the root element of the XML document.

  • … and the [ … ] is the DTD.

External Document Type Declaration

<!DOCTYPE root-element SYSTEM "file.dtd">
<!DOCTYPE root-element SYSTEM "file.dtd" [ … ]>
<!DOCTYPE root-element PUBLIC "Public Identifier" "file.dtd">
<!DOCTYPE root-element PUBLIC "Public Identifier" "file.dtd" [ … ]>

Where …

  • … the root-element is the name of the root element of the XML document.

  • … and the "file.dtd" is the path to the DTD.

  • … and the [ … ] is some additional internal DTD.

  • … and the "Public Identifier" is the public identifier of the DTD.

— David Wolf