Site Archive (Complete)
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Spurl
Slashdot
Y! MyWeb
Blink
Furl
January 01, 2002
Our Last, Best Hope for Clean Code

Peter Wiggin

WebReview.com: XHTML: Our Last, Best Hope for Clean Code

Rank: 2

What is XHTML?

•XHTML is a stricter, cleaner version of HTML.

•Why do we need cleaner code? Current browsers are bloated with code to handle sloppy or proprietary HTML. As more devices read web content (handhelds, set-top boxes, pagers), we'll need more compact browsers.

•XHTML documents are all lowercase.

•All tags, including empty elements, must be closed.



XML is a hot topic among web developers. Its promise of a standardized markup that separates display and layout code from syntax really hits home if you've ever experienced the frustration of parsing loose code.

But that's just one example of how a strict, standardized markup standard can make programming easier. As we watch the growing trend of portable web-enabled devices, we realize they will require a compact code using standardized markup. Getting to that point, however, isn't going to be easy.

Whether your site has 10 pages or 10,000, it's likely that the HTML code is a mix of standard HTML and browser-specific, proprietary markup. If you've been thinking about making the transition to XML, or even just standardizing your HTML code, here's the solution: XHTML (Extensible Hypertext Markup Language).

XML + HTML = XHTML (sort of)

Let's take a quick look at how these markup languages fit together.

  • HTML is a markup language described in SGML (Standard Generalized Markup Language).
  • XML is a restricted form of SGML, removing many of SGML's more complex features, but preserving most of SGML's power and commonly used features.
  • XHTML is the reformulation of HTML 4.0 as an application of XML.

The W3C (World Wide Web Consortium) has taken the logical step of expressing the HTML 4.0 standard in XML instead of using the more complicated SGML.

The minute details aren't too important for the average web coder, but the main difference is found in the document type definitions (DTDs) used by HTML and XHTML. A DTD, according to the W3C, is "a collection of declarations that, as a collection, defines the legal structure, elements, and attributes that are available for use in a document that complies to the DTD."

In other words, it's a definition of what is legal syntax in HTML (or XHTML) and what isn't. The DTD for XHTML is more restrictive than the DTD for HTML because XML is more restrictive than SGML.

The W3C gives two main reasons for recommending XHTML as the next step from HTML 4.0. First, XHTML, since it's an XML application, is designed to be extensible—that's the "X" in all the acronyms. This means that new tags or "elements" in the official W3C jargon can be added without altering the entire DTD that the document is based on.

Second, XHTML is designed for portability. web browsers have become behemoths of code bloat. You name it, there's code in the newest browsers to do it. But according to some estimates cited by the W3C, by 2002, 75 percent of web document viewing will be through non-desktop devices like palm computers, televisions, toasters, and other alternative platforms, not through browsers on PCs. Your web-enabled toaster will have less room for bloated code, and its browser will need to be able to count on standards-based documents. It may not be able to display current incarnations of HTML because of the non-standard code involved.

To help you see the main differences between HTML and XHTML, we've included a number of examples in the following section, "Differences." You'll see that most of the variances are simply stricter definitions of common HTML tags.

There are, however, some new features, which we cover in the third section, "What's New."


XHTML Part 2: Differences
What are the differences when coding in XHTML? For many developers the changes are minor, that is, unless you love uppercase tags.

XHTML Part 3: What's New
XHTML does require a doctype declaration and won't allow open <br> tags. But the changes are less different than you think.

DR. DOBB'S CAREER CENTER
Ready to take that job and shove it? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:
    MEDIA CENTER  more
    NetSeminar
    Fully Utilize Embedded Hardware Potential and Create Advanced User Interfaces Fast
    Processing power and display capabilities previously limited embedded system development. Now larger, full-color displays and powerful hardware running advanced operating systems are affordable. To take advantage of this new opportunity high level programming is required. Learn how with a complete set of tools, such as Trolltech's C++ development framework, fully utilizing hardware potential and creating advanced user interfaces can be achieved quickly and efficiently. Event Date: Wednesday, May 28, 2008
    Amp Up Your Continuous Integration Builds
    Amp up your continuous integration build process by increasing the frequency of your build loop. Learn from experts how to create a build that can quickly adapt to source code changes and drive down build times from hours to minutes. Event Date: Thursday, May 22, 2008
    Become a Better Build Detective: Effective Techniques for Debugging Makefiles
    This Webcast will uncover some of the most common Makefile errors and provide specific, proven techniques for fixing them. If command or syntax errors have been a mystery for you, this is a discussion you won't want to miss. Event Date: Wednesday, May 28, 2008
                                   

    ♦ sponsored
    EVENTS

    July 21-24, 2008
    Chicago, IL
    Find real-world solutions to your biggest software architecture challenges at Architecture & Design World 2008. Register by June 20 and save up to $300!
    The Dobbs Challenge
    THE DOBBS CHALLENGE
    Download the Dr. Dobbs Challenge game for either Windows or Windows Mobile and modify it using Visual Studio 2008. Win $10,000!
    INFO-LINK

    Resource Links:




    Related Sites: DotNetJunkies, SD Expo, SqlJunkies