31.3. XHTML Document Declarations

Every XHTML file must begin with
declarations that tell the browser which versions of XML and XHTML
are used in the document. The browser uses this information to
display the document correctly. In Chapter 9, "Structural HTML Tags" we
saw how a DOCTYPE declaration can be added to the
beginning of an HTML document. For XHTML, this element is required.

Let's look at this sample one element at a time. The document
begins with an XML declaration (beginning with
<? and ending with ?>)
that tells the XML processor that the document uses XML Version
1.0.[16] The encoding attribute
specifies the 8-bit Unicode character set (the most common). Be sure
that the encoding value matches the character set used in your
document (see Chapter 7, "Internationalization" for more information on
character sets).

[16]Some older browsers (such as Navigator 3) that
don't understand XML display the XML declaration text as part
of the displayed content. Therefore, if you're sending XHTML
documents to these older browsers, you may need to omit this
part.

The next element is the DOCTYPE declaration (the
same as we've seen in XML and even regular HTML documents) that
references the Transitional DTD, both by a public identifier and via
a URL. If your document follows the strict XHTML version, use this
declaration:

Finally, there are a few more directions added within the
<html> tag for the document. The
xmlns attribute specifies the primary namespace
for the document. A namespace is a unique collection of tags and
attributes that can be referenced by the browser. Namespaces are
discussed in Chapter 30, "Introduction to XML". More than one namespace
may be referenced within a document, for instance, if the document
contains other XML applications such as Scalable Vector Graphics
(SVG) or MathML.

The lang attribute is used to declare that the
document language is English, for both the XML and XHTML namespaces.