|By Molly E. Holzschlag||
|March 7, 2001 12:00 AM EST||
The XML developer doesn't have to be convinced of XML's strength. You've heard it a million times: it's all about the data. The same is true on the client side. XHTML strongly embraces the separation of content and presentation, and brings XML's syntactical logic, as well as extensible opportunities, to the client-side table.
XHTML 1.0, a reformulation of HTML as an XML application, has been the W3C's Web markup recommendation (www.w3.org/TR/xhtml1/) since January 26, 2000. That's more than a year now, but client-side authors and developers of popular authoring software have been slow on the take. Much of the problem lies in the fact that XHTML is misunderstood and not well publicized. Some client-side authors don't see it as having any special advantages, and many critics have claimed that XHTML simply won't be widely adopted. This may well be proven out. XHTML has been almost completely missed by the vast majority of entry- and mid-level professionals.
Ignoring or overlooking XHTML is problematic for the professional developer. Whether it's a useful client-side methodology remains a personal question. However, knowing what it is, why it is, and how it may or may not effectively aid the work you do allows you to make an informed, empowered decision about the technologies you choose to employ.
XHTML: What and Why
In simple terms, writing documents in XHTML means that instead of authoring that old familiar HTML, you are in essence writing XML. XML, in XHTML 1.0, employs HTML as its vocabulary. So elements and attributes are not arbitrary - they're drawn directly from HTML. Similarly, XML syntax rules are applied.
But how does this help client-side authors? The answer is simple. How many of you have honestly paid much attention to the HTML you generate? Some of you will certainly say you do, but most developers - like most Web designers - are guilty of a slapdash attitude toward HTML. It's not your fault. HTML has become sloppy, in part because it's been bent in many directions to accommodate the rapid growth of the Web. And browsers are extremely forgiving of poor markup. Nothing has demanded that you write clean documents because for the most part you haven't had to.
The problems resulting from this are manifold. First, there's no consistency in markup from one HTML author to the next. They've each got their own methodology - some write elements in uppercase, others in lowercase. Quotes are sometimes in use, sometimes not. Looking under the hood at even the most high-end site is usually not a pretty experience. So adding a little syntactical rigor to the mix via XHTML gets authors on the same page, if you'll pardon the pun. That can make for a much smoother workflow among teams.
XHTML 1.0 focuses heavily on getting markup cleaned up. But XHTML has another goal, too, and that's to extend to user agents beyond the Web browser: PDAs, smart phones, set-top boxes, and other alternative and wireless devices. Streamline and strengthen the markup, and you've got a stronger base from which to extend it. That's a logical and rational idea.
Another argument made in XHTML's defense - and it's a controversial one but I buy into it - is that it helps the client-side author who has XML phobia to begin moving into the XML arena via familiar means. I like this argument because as an educator, I've seen proof that it works. Take entry- or mid-level Web authors, teach them XHTML, and suddenly you can also teach them other XML applications: WML, SMIL, SVG. The light bulb goes on because they're operating in an environment that's familiar - HTML. The XML kind of sneaks in via document structure and syntactical rules.
Brass Tacks: XHTML
To gain a better idea of how XHTML 1.0 works, let's first examine its document structure.
Ideally, an XML document begins with an XML declaration:
<?xml version="1.0" encoding="UTF-8"?>But XHTML documents are most often viewed using popular Web browsers, which in some cases will render anything with an XML declaration as text. So for XHTML 1.0, the W3C recommends (but does not require) that the XML declaration be intact. Most Web authors leave it off.
Next comes the DTD, which is required. With XHTML 1.0, you can choose from three public DTDs: strict, transitional, or frameset. Developers working with HTML 4.0 will be familiar with these DTDs and know that the strict DTD uses the most limited set of elements and attributes of the three, basing much of its selection on the idea that presentation and structure must be separate. So you won't find the font element in a strict document. Transitional documents, however, are more flexible, understanding that Web authors must make some accommodations in order to achieve the best interoperability possible. Frameset documents are limited to framesets and can employ elements from strict or transitional DTDs.
For a strict XHTML 1.0 document, you'll use the following declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-strict.dtd">
If you want to write your document in accordance with the transitional DTD, you'll use:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd">Finally, if you're authoring a frameset, you'll use this declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-frameset.dtd">It's important to remember that there are no exceptions to the rule here. You must declare the proper DTD in your XHTML 1.0 document.
Now it's time to add the namespace to the root. In XHTML 1.0 the root element is html. The root and namespace is also a requirement, and is written as follows:
<html xmlns="http://www.w3.org/1999/xhtml">Listing 1 shows a strict document template using the XML declaration. In Listing 2 I show a transitional document template using a meta workaround for document encoding should you choose not to use the XML declaration.
Get Tough: XHTML Syntax
Now that you've got the document structure down, it's time to explore the syntactical rules that XHTML 1.0 embodies:
- Must be well formed
- Is case specific
- Insists on closing tags for nonempty elements, and termination of empty elements with a trailing slash
- Demands that all attribute values be quoted Let's take a closer look.
Remember, Web browsers are built to forgive. That's one reason they're so bloated; they have to be able to interpret such a wide variety of markup styles. And most browsers will forgive ill-formed syntax. Try the following poorly formed bit of HTML in a browser:
<b><i>An ill-formed bit of HTML</b></i>In common browsers such as MSIE and NN, this markup will appear in both bold and italics. However, if you examine the HTML, you'll see that the tags are improperly nested. If this markup were well formed, the tags would nest properly:
<b><i>A well-formed bit of HTML</i></b>XHTML 1.0 must be well formed to be valid XHTML. A little trick I use to make sure I've nested my tags properly is to draw an imaginary line from the opening tag to its closing companion. If the lines don't intersect, it's properly nested and therefore well formed. Intersecting lines will indicate improperly nested, ill-formed markup.
As you're already aware, XML is case sensitive:
<product>are two different tag sets.
HTML, on the other hand, is not case specific:
<P align="right">XHTML is case specific. In every instance all elements and attribute names must be lower case:
</P> is the same as: <p ALIGN="right">
<p align="right">Note that attribute values can be in upper- or lowercase as necessary to accommodate file names, code strings, and URIs.
XHTML 1.0 adopts the XML method of closing all nonempty elements and terminating empty elements with a trailing slash. In HTML you can write the following:
<li>list item 1
<li>list item 2
<li>list item 3
but in XHTML, you must close the nonempty element:
<ul>One of the more obvious places this occurs is with the paragraph <p> tag. You must close all nonempty elements, no exceptions.
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
If an element is empty (no content), it must terminate. In XML this is done by using a trailing slash as follows:
<br/>But many Web browsers will choke on this method and subsequently not render a page or render it improperly. a workaround is to add a space before the slash. This allows all empty elements to be properly rendered. A few examples:
<img />As with nonempty elements, there can be no exception to the rules. You must terminate the element accordingly.
Quoth the Attribute Value...
One of the more frustrating things about HTML - at least to my eye - is the arbitrariness of attribute value quoting. In HTML it's a now-you-see-it, now-you-don't phenomenon. So you can have:
<img src="my.jpg" border="1" width=400 height=200 alt="company logo">or any combination of attribute value quotations you like. In most instances a browser will properly render the markup whether you've quoted the attribute value or not.
XHTML insists that you quote all attribute values, leaving nothing to chance:
<img src="my.jpg" border="1" width="400" height="200" alt="company logo" />
Not so hard, really
as you can now see, XHTML 1.0 is really no great challenge. Does it mean employing a little more care when creating documents? Yes. Does it mean watching your syntax? Absolutely. But with a few minor adjustments you can have clean markup that works in today's browsers with as close-to-perfect interoperability as HTML and still complies with W3C recommendations.
Advancing Notions: Modularization of XHTML
So what's a little cleanliness, anyway? Critics of XHTML have pointed out that changing habits just to write cleaner documents doesn't provide much incentive. It's time consuming and why on earth would you want to go back and rewrite hundreds, possibly thousands, of Web documents just to comply with a W3C recommendation when those documents function perfectly well? I can't, and won't, argue this point. It's too strong an argument. But if you're interested in moving toward extensibility, want to create consistent documents organization-wide, and want to assist your client-side authors in expanding their markup horizons, working with XHTML makes sense.
While XHTML 1.0 offers little option for extensibility - you've got three set DTDs and a specific namespace - the modularization of XHTML does offer expansion. Modularization of XHTML, which allows for the use of XML DTDs and provides the means to create subsets and extensions to XHTML, takes XHTML 1.0 from its limited place closer to its goal of working for numerous user agents. As of this writing, modularization of XHTML is a Candidate Rec-ommendation of the W3C (www.w3.org/TR/2000/CR-xhtml-modularization-20001020/).
Modularization of XHTML is a decomposition of HTML as we know it today. Instead of lumping markup methods such as managing text, images, tables, and forms, modularization breaks these things into separate modules. Then, using XML DTDs (an implementation of XML schemas is also under discussion), authors can pull together a subset of XHTML using only those modules necessary to accomplish a given task.
If you put modularization in the context of alternative device design, the rationale for XHTML begins to make a lot of sense. Many alternative devices simply don't have the processing, RAM, and video power to handle HTML's original functions. So why have all the overhead? A streamlined markup language using only those modules necessary for the device means faster, customizable delivery to equally streamlined optimized user agents.
A perfect example of modularization exists in XHTML Basic (www.w3.org/TR/xhtml-basic/), a subset of XHTML 1.1, made up of specific modules that apply to wireless devices such as PDAs, smart phones, and smart pagers. These devices are limited in their processing power, so XHTML Basic supplies those modules only for markup that make sense, such as text, links, images, very basic tables, and forms. Frames or scripting demand processing power, so they're left out of the subset. XHTML Basic, at this writing a Proposed Recommendation of the W3C, looks just like XHTML, but of course any element that falls into a module not set forth in the recommendation can't be used in a valid XHTML Basic document. However, you can extend XHTML Basic if you want to. This enables the creation of additional subsets and extensions.
Listing 3 shows a simple XHTML Basic page suitable for display on a small, wireless device such as a PDA. The listing clearly illustrates how XHTML Basic uses the structural elements set forth in XHTML 1.0, only this time the DTD that's declared is for XHTML Basic itself. The namespace is the same, as are the syntactical methodologies.
Bring It On Home
The developer who's empowered with knowledge can make better decisions. Whether you embrace client-side XML in the form of XHTML is up to you. But a careful survey of your needs and directions will help answer the question of whether XHTML will be useful in your unique situation. Being aware of what's happening with XHTML and its goals will keep you at the ready should your circumstances require you to develop not only for the Web of tomorrow, but for the wireless world and beyond.
- The Odd Couple: Marrying Agile and Waterfall
- Fanning the Flames of Agile
- Big Data, Cloud and Mobile - Converging Technology Trends
- April and May 2014 Server and StorageIO Update newsletter
- Big Data Expo 2014 Silicon Valley Call for Papers Now Open
- WSO2 Introduces Industry’s First Enterprise Identity Bus With the Launch of WSO2 Identity Server 5.0
- The Butterfly Effect Within IT
- Setting the Bar for Agile Architecture
- Jim Miller at ImageWare Systems, George Romas at HP, Jody Ross at AMAG, + March Networks and StrikeForce Featured in SecuritySolutionsWatch.com Interviews
- The Agile PMO
- The Linux Foundation's Core Infrastructure Initiative Announces New Backers, First Projects to Receive Support and Advisory Board Members
- Why End-User Experience Is Important
- .CLUB Domain Name Extension Now Available for General Registration
- FOSE Expo to Feature Cutting-Edge Solutions from Top Government Technology Vendors
- AMAG, HP, ImageWare Systems, March Networks and StrikeForce Discuss Security Solutions in SecuritySolutionsWatch.com Interviews
- The Odd Couple: Marrying Agile and Waterfall
- Flexera Software’s InstallShield 2014 Release Introduces New Support of Cloud and Virtualised Installations, High-DPI Displays and Touch Devices, and Agile Development
- Learn How You Can Easily Extend Your Infrastructure with Microsoft Azure
- Fanning the Flames of Agile
- FlexNet Manager Suite Wins CODiE Award for Best Asset Management Solution - 4th CODiE Award for Flexera Software
- Moore’s Law Gives Way to Bezos’s Law
- Flexiant Acquires Besol’s Tapp Multi-Cloud Management Technology and Business
- Big Data, Cloud and Mobile - Converging Technology Trends
- Ten Answers Regarding Mobile App Testing
- Google Maps and ASP.NET
- Converting VB6 to VB.NET, Part I
- How to Write High-Performance C# Code
- Where Are RIA Technologies Headed in 2008?
- Crystal Reports XI & How It Has Changed
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Programmatically Posting Data to ASP .NET Web Applications
- Implementing Tab Navigation with ASP.NET 2.0
- AJAX World RIA Conference & Expo Kicks Off in New York City
- The Top 250 Players in the Cloud Computing Ecosystem
- i-Technology Viewpoint: "SOA Sucks"
- .NET Archives: Getting Reacquainted with the Father of C#