Moving from HTML to XHTML
Most of the changes required to turn an existing HTML document into an XHTML document involve making the document well-formed. For instance, given a legacy HTML document, you’ll probably have to make at least some of these changes to turn it into XHTML:
Add missing end-tags like
</p>and</li>.Rewrite elements so that they nest rather than overlap. For example, change
<p><em>anemphasizedparagraph</p></em>to<p><em>anemphasizedparagraph</em></p>.Put double or single quotes around attribute values. For example, change
<palign=center>to<p align="center">.Add values (which are the same as the name) to all minimized Boolean attributes. For example, change
<input type="checkbox" checked>to<inputtype="checkbox" checked="checked">.Replace any occurrences of
&or<in character data or attribute values with&and<. For instance, changeA&PtoA&Pand<ahref="http://www.google.com/search?client=googlet&q=Java%20XML">to<ahref="http://www.google.com/search?client=googlet&q=Java%20XML">.Make sure the document has a single root
htmlelement.Change empty elements like
<hr>to<hr />or<hr></hr>.Add hyphens to comments so that
<! this is a comment>becomes<!-- thisis a comment -->.Encode the document in UTF-8 or UTF-16, or add an XML declaration that specifies in which character set it is encoded.
XHTML doesn’t merely require well-formedness; it also requires validity. In order to create a valid XHTML document, you’ll need to make ...