Next page Previous page Start of chapter End of chapter

Document Type Declaration

An XML document is associated to a DTD with a document type declaration. This is a declaration that should follows the XML declaration in the XML document. It has the following form:

<!DOCTYPE root [DTD]>

where DOCTYPE is the keyword for document type declaration, root is the name of the document element of the XML document, and DTD is the actual set of rules that defines the DTD.

An XML document may include a reference to the DTD, instead of the DTD itself. This is useful when the same DTD is shared by different documents. The document type declaration changes as follows:

<!DOCTYPE root KEYWORD "URI">

where KEYWORD can be either SYSTEM or PUBLIC. If the keyword is SYSTEM then the DTD is specified outside the document by means of a Uniform Resource Locator (URL). The URL can be either absolute or relative. For instance, the following declaration specifies that the document element is person and that the DTD is contained in a local file named Turing.dtd that is stored in the same folder of the XML document:

<!DOCTYPE person SYSTEM "Turing.dtd">

If the keyword is PUBLIC then the DTD is specified outside the document by means of a Uniform Resource Name (URN). The URN is a name that uniquely identifies the XML application. For instance, the following declaration specifies that the document element is html and that the DTD is the strict version of XHTML 1.0, whose URN is -//W3C//DTD XHTML 1.0 Strict//EN. Notice that a backup URL is also added in case the declared DTD is not available on the local file system:

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

Finally, you can mix internal and external DTD subsets using the following syntax:

<!DOCTYPE root KEYWORD "URI" [DTD]>
Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet