XML Document Type Definitions (DTD)

A document model defines the vocabulary and grammar rules for a particular markup language. Here are some examples of what you can achieve by using a DTD model:

Declaring a DTD

There are two kinds of DTD declarations: internal or external. One can combine them though.

Internal declarations

The syntax for the internal subset of DTD is:

<!DOCTYPE root
[
  declarations
]>

Here root is the name of the document's root element and declarations are the statements that comprise the DTD.

External declarations

In an external declaration the declarations are placed in an external file that is accessed from the XML document. They can be of two types: system and public. The system identifier allows you to specify the location of an external subset.

<!DOCTYPE root SYSTEM "uri">

The uri (Universal Resource Identifier) can be a system file or a document on another server.

Examples:
<!DOCTYPE root SYSTEM "rules.dtd">
<!DOCTYPE root SYSTEM "http://cs2.uwsuper.edu/sb/351/XML/rules.dtd">

A public identifier is added to provide the public name of the DTD:

<!DOCTYPE root PUBLIC "id" "uri">

Here the id is a name of a public identifier and the uri is a location of the DTD in case the XML parser cannot process the public identifier. Many browsers including the Internet Explorer and Firefox have built in XML processors that are aware of several public DTDs.

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

This is a standard XHTML DTD with id = "-//W3C//DTD XHTML 1.0 Transitional//EN". If this DTD is not built into a specific browser, it still can be accessed at the provided location.

Combined declarations

Both system and public DTDs can be extended by internal ones. In the later case, the internal declarations have a preference in processing and can override the corresponding external declarations. The syntax is:

<!DOCTYPE root SYSTEM "uri"
[
  declarations
]>

or, respectively,

<!DOCTYPE root PUBLIC "id" "uri"
[
  declarations
]>