Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition)

Although it's great to focus on creating new web pages from scratch using XHTML, the reality is that at some point you are likely to encounter HTML documents that you will want to convert to XHTML. Fortunately, it isn't too terribly difficult to bring HTML 4 documents up to par with the XHTML 1.1 specification. You've already learned about the ways in which XHTML documents differ from HTML documents. These differences become your guide to converting HTML to XHTML.

Following is a checklist to use as a guide while performing the conversion from HTML to XHTML:

1.

Add a document type declaration that declares the XHTML 1.1 DTD.

2.

Declare the XHTML 1.1 namespace in the html element that matches the DTD.

3.

Convert all element and attribute names to lowercase.

4.

Match every start tag with an end tag.

5.

Replace > with /> at the end of all empty tags.

6.

Enclose all attribute values in quotes (").

7.

Make sure that all elements and attributes are defined in the XHTML 1.1 DTD; use CSS styles to replace deprecated presentation tags.

8.

Convert special characters to entity references; for example, " becomes " (see Table D.1 for more details).

Table D.1. Characters to Avoid Using in XHTML Pages

Replace This…

With This…

& (ampersand)

& or &

" (quotation/inch mark)

" or "

< (open angle bracket)

&lt; or &#60;

> (close angle bracket)

&gt; or &#62;

[ (open square bracket)

&#91;

] (close square bracket)

&#93;

' (apostrophe/single quote)

&#39;

Did you Know?

If you have a number of HTML pages that you'd like to convert to XHTML-compatible format, I strongly recommend that you download the free HTML-Kit software from http://www.chami.com/html-kit/. This free program includes a module called HTML-Tidy, which automatically changes HTML to conform to the rules mentioned here and also reports any other problems or incompatibilities it finds. HTML-Kit is also a friendly and well-designed text editor with many handy features for writing new XHTML pages. (One caveat: HTML-Tidy changes the line breaks and spacing of your code, so you may have to do some reformatting by hand if you like to neatly indent your code.)

After you've converted your pages over to XHTML, you will want to validate them to make sure that the conversion was a complete success. The W3C provides a free online validation service you can use to see whether your pages adhere completely to the official XHTML standard. The validation service, located at http://validator.w3.org/, allows you to browse XHTML files on your own computer for validation, as well as files that are already published on the Web. I strongly encourage you to try out the validation service because it represents the final word on the accuracy of XHTML code.

The good news in regard to XHTML document conversion is that this book has already taught you good enough coding habits that conversion shouldn't be a problem for your new web pages. And even when tackling existing pages that don't conform to XHTML, you should be able to methodically tackle the conversion by following the steps mentioned in this appendix. If you carry out each of these steps, you should arrive at a legitimate XHTML document that conforms to all the rules of the XHTML 1.1 standard.

Категории