Creating XHTML Documents
For the most part, creating an XHTML document is no different from creating an HTML document. Using your favorite text editor, simply add the markup elements to your document’s contents in the right order, and display it using your favorite browser. To be strictly correct (“valid,” as they say at the W3C), your XHTML document needs a boilerplate declaration up front that specifies the DTD you used to create the document and defines a namespace for the document.
Declaring Document Types
For an XHTML browser to correctly parse and display your XHTML document, you should tell it which version of XML is being used to create the document. You must also state which XHTML DTD defines the elements in your document.
The XML version declaration uses a special
XML processing directive. In
general, these XML directives begin with <?
and
end with ?>
, but otherwise they look like
typical tags in your document.[96]
To declare that you are using XML Version 1.0, place this directive
in the first line in your document:
<?xml version="1.0" encoding="UTF-8"?>
This tells the browser that you are using XML 1.0 along with the
8-bit Unicode character set, the one most commonly used today. The
encoding
attribute’s value should
reflect your local character set. Refer to the appropriate ISO
standards for other encoding names.
Once you’ve gotten the important issue of the XML version squared away, you should then declare the markup language’s DTD:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...
Get HTML & XHTML: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.