JavaScript EditorDebugger script     Dhtml css 



Team LiB
Previous Section Next Section

XHTML Compatibility Guidelines

There are two current versions of HTML: HTML 4.01 and XHTML 1. XHTML 1 was created to provide a version of HTML that conforms to XML (Extensible Markup Language) and SGML (Standard Generalized Markup Language). XHTML 1 relies upon HTML 4.01 for all of its element and attribute definitions.

When the initial version of XHTML (XHTML 1.0) was introduced, it was a standalone specification. Since then, however, the W3C has redefined XHTML as composing a group of modules: XHTML 1.0, XHTML 1.1, and XHTML Basic. XHTML modules are not sequential versions of the XHTML specification but are parallel specifications. XHTML 1.1 is intended as allowing for the integration of other modules, such as MathML (Mathematical Markup Language), with XHTML documents. XHTML Basic is intended for marking up documents for presentation by Web clients with limited user-interface capabilities, such as PDAs, cell phone displays, TV set-top boxes (WebTV, for instance), and so on.

Declaring the XHTML Document Type

You can declare an XHTML document to be in conformance with the strict, transitional, and frameset definitions of XHTML 1.0. These operate in the same fashion as when creating HTML 4.01 documents. The following full DocType declarations can be used when creating an XHTML 1.0 document:

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

or

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

or

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

Differences between XHTML 1.0 and HTML 4.01

Here is a summary of the main differences between the two markup languages:

  • Although implied end tags are allowed for several HTML tags, all end tags must be included for container elements in XHTML. When creating lists, for instance, nested UL, OL, or P elements must be inserted inside of the closing </li> element.

  • Empty tags must include the "/" character at the end of the tag. The HTML <br> must be written as <br /> in XHTML, for instance.

  • Although in HTML you can type HTML element and attribute names any way you want (<html>, <Html>, and <HTML> all being the same tag), all XHTML elements must be typed in all lowercase. (In this book, I've also stressed typing HTML element and attribute names in lowercase, to facilitate the future upgrading of HTML documents to XHTML documents.)

  • In HTML, quoting attribute values is often optional, but in XHTML it is required. Thus, whereas align=right is allowed in HTML, in XHTML this must be written as align="right". (In this book I've stressed quoting attribute values.)

  • HTML allows including minimized attributes, such as the NOSHADE attribute of the HR tag, but XHTML does not. What can be written in HTML as <br noshade>, for instance, must be written in XHTML as <br noshade="noshade" />. In XHTML, all minimized attributes (compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, and defer) should be expanded. Note, however, that although this will not cause any problems in HTML 4.0-compliant browsers, some older browsers may fail to recognize the expanded attribute.

  • HTML 4.01 allows the omission of the start and end tags for the HTML, HEAD, and BODY elements, but inclusion of both the start and end tags for these elements is required in XHTML 1.0.

  • In HTML 4.01, the TBODY element can be implied as the totality of rows within a table, with both its start and end tags omitted. Styles created for the TBODY element will be applied to the table as a whole. In XHTML 1.0, however, the TBODY element start and end tags are required.

  • The NAME attribute in HTML is superseded by the ID attribute in XHTML. Whereas <a name="section1"></a> can be used to define a target anchor in HTML, <a id="section1"></a> should be used in XHTML. The NAME attribute has been included in XHTML for transition purposes, but will be obsoleted in a future version of XHTML. Both ID and NAME can be used for the same element in XHTML documents, for compatibility with browsers that do not recognize XHTML documents.

  • Although align="justify" is allowed for the P and Heading elements in HTML 4.01, it is not allowed in XHTML 1.0 documents.

  • The LANG attribute in HTML is superseded by the XML:LANG attribute in XHTML. Whereas lang="en" can be used to specify English as the language in HTML, xml:lang="en" should be used in XHTML. The LANG attribute has been included in XHTML for transition purposes, but will be obsoleted in a future version of XHTML.

  • In HTML 4.01, the standalone ampersand (&) and left angle bracket (<) characters are allowed in attribute values and the document body, but in XHTML 1.0, these characters must be replaced by their entity codes (&amp; and &lt;). This is also true with embedded scripts that may contain these characters as operators. The way around that is to create and link to an external script file.

  • Comment tags should not be used inside STYLE or SCRIPT elements to hide content from non-supporting browsers, since XHTML documents may potentially be parsed by either a browser's HTML parser or its XML parser, with an XML parser not recognizing the HTML comment codes. This is not currently a problem, since all current browsers parse XHTML documents using their HTML parser, but it could be a problem in the future.

  • Because an XHTML document is also an XML document, the root element (the HTML element) must contain an XMLNS declaration for the XHTML namespace. For instance:<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

  • When specifying the character encoding for an XHTML 1.0 document, use both an XML declaration (<?xml version="1.0" encoding="EUC-JP"?>, for instance) at the top of the document and a META tag HTTP-EQUIV statement (<meta http-equiv="Content-type" content='text/html; charset="EUC-JP"' />, for instance) nested in the HEAD element. The XML declaration will take precedence in XHTML browsers, but will be ignored by HTML browsers.

Note 

FIND IT ONLINE
Including guidelines or directions for creating XHTML 1.0-compliant documents is not part of the purpose of this appendix. If you're interested in writing XHTML 1.0-compliant documents, you should first thoroughly read the W3C's XHTML 1.0 recommendation at www.w3.org/TR/xhtml1/.


Team LiB
Previous Section Next Section


JavaScript EditorDebugger script     Dhtml css 
R7