Document Types

An XHTML Document Type Definition (DTD) describes in precise, computer-readable language the syntax or grammar that is allowed for XHTML markup. When an XHTML document is created, the DTD that it conforms to is declared at the top of the document. XHTML 1.0 specifies three XML document types that correspond to the three HTML 4.0 DTDs: Strict, Transitional, and Frameset. XHTML 1.1 and XHTML 2.0 may also be specified as DTDs.

Here is an example of each DTD declaration:

XHTML 1.0 Strict

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

XHTML 1.0 Transitional

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

XHTML 1.0 Frameset

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

XHTML 1.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

XHTML 2.0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml2.dtd">

The DTD definition is placed at the beginning of the document before the opening <html> tag, as shown in Example 12-1.

Example 12-1. A document defined as xhtml 1.0 strict

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>

<title>Document Type Declaration Example</title> </head> <body>

<p>The content of the page goes here.</p> </body> </html>

The opening line:

<?xml version="1.0" encoding="UTF-8"?>

This isn't strictly required unless you're using a different character encoding than UTF-8.

Was this article helpful?

0 0

Post a comment