Saturday, January 26, 2013

3. Expanding into XHTML


The latest version of HTML is known as XHTML, short for eXtensible HTML. XHTML is based on
XML and, as such, has a more rigid syntax than HTML. For example, tags that do not enclose
content—the so-called empty tags—are written differently. In HTML, a line-break tag is
<br>
whereas in XHTML, the line-break tag is
<br />
Note the additional space and the closing slash. Other differences include an opening XML
declaration as well as a specific doctype tag placed before the opening <html> tag. All tags
must be in lowercase, and all attribute values must appear in quotes, (but not necessarily
lowercase) as follows:
<table align=”RIGHT”>
Dreamweaver makes it easy to code in XHTML, and even to convert existing pages from
HTML to XHTML. To work in XHTML from the ground up, select the Make Document XHTML
Compliant option on the New Document category of Preferences (available when you choose
Edit ➪ Preferences). Selecting this option will automatically select an identical option on the
New Document dialog box (File ➪ New)—which, if necessary, you can disable on a case-bycase
basis. Once a document has been set as an XHTML file, all the tags are written in the
proper style.
To switch an HTML page to an XHTML one, choose File ➪ Convert ➪ XHTML. The conversion
is automatically applied to the current document; there is no standard method to convert an
entire site.
Since Dreamweaver has taken the pain out of using XHTML, the question is, should you code
in XHTML or HTML? As in most situations, it depends. Many larger companies that work
extensively in XML require well-formed XHTML pages. As the latest version of the Web’s core
language—and recommended by the W3C—you’ll be perfectly poised for the future. One
aspect of the future is the proliferation of Internet devices other than the computer: PDAs,
cell phones, and set-top boxes, among others. XHTML is far more portable to these types of
devices than HTML.


doctype and doctype Switching

The very first element of an HTML page—even before the <html> tag—is, increasingly, a
doctype declaration. As the name implies, a doctype declaration specifies the language or,
more specifically, the DTD (Document Type Definition) in use for the file that follows. To
validate their page, many authors include doctype statements like the following:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
This doctype is inserted by default when Dreamweaver creates a new static HTML page.
The latest—in fact, the last—version of HTML recommended by the W3C is version 4.01.
After this version, the W3C recommended the switch to XHTML.
Recent browser versions have begun inspecting the doctype element in order to determine
how the page should be rendered. Engaging in a practice known as doctype switching, these
browsers (Internet Explorer 5 on the Macintosh, Internet Explorer 6, and Netscape 6) work in
two modes: strict and regular. When in strict mode, a page must be well-formed and validate
without error to be rendered properly. Strict rendering is more consistent across browsers.
The regular mode is far looser and more forgiving in how the page is coded; however, your
page is more likely to be rendered differently in the varying browser versions.
You can ensure that your pages are rendered in the regular mode in a number of ways:
✦ Do not include a doctype declaration at all.
✦ Use a doctype declaration that specifies an HTML version earlier than 4.0.
✦ Use a doctype declaration that declares a transitional DTD of HTML 4.01, but does not
include a URL to the DTD.
To trigger a browser’s strict rendering mode:
✦ Use a doctype declaration for XML or XHTML.
✦ Use a doctype declaration that declares a strict DTD of HTML 4.01.
✦ Use a doctype declaration that declares a transitional DTD of HTML 4.01 that includes a
URL to the DTD.
When including a URL to the DTD, the doctype looks as follows:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
You have several alternatives in Dreamweaver for including whichever doctype you choose.
Hand-coding is a sure but tedious method; the doctype statement is somewhat cumbersome
and certainly not easy to remember precisely. You could also alter the standard HTML page by
changing the Default.html file found in your Configuration\DocumentTypes\NewDocuments
folder.
Note

No comments:

Post a Comment