|
|
![]() WORKSHOP Extensible HyperText Markup Language (XHTML) Many of you probably heard that HTML 4.01 (http://www.w3.org/TR/html4/) is the last HTML standard coming out of the W3C (World Wide Web Consortium) and that the future standards will focus on XML. But, then you might have heard that Extensible HyperText Markup Language (XHTML) 1.0 became a W3C Recommendation on January 26, 2000. See http://www.w3.org/TR/xhtml1/. So what's the difference between HTML and XHTML and why this new standard? To answer those questions, let's consider what's happening in the Web development world.
To summarize, with XHTML W3C is trying to achieve the following:
How is XHTML different from HTML?XHTML is essentially the same as HTML, but is rewritten as an application of XML 1.0 with some good XML features thrown in. The current versions of HTML are written as an application of SGML (Standard Generalized Markup Language). Writing it as an XML application helps achieve both the goals of extensibility and "cleaner" markup. If you are not familiar with XML, I'd suggest reading Extensible Markup Language: Why the Fuss?. So let's see how we can extend existing HTML code with new markup designed specifically for mathematical expressions. Here's an example from W3C spec:
In the above example, the text marked red is not part of the HTML specification. However, it can be used in an XHTML document by specifying the namespace using the xmlns -- that is, the XML Namespace. It lets an XHTML-compliant browser know that the tags within the <math> and </math> tags are different from the rest of the document. Let's take a simpler example to better understand the significance of namespaces. We know that in an HTML document the <title> tag is used to denote the title of the Web page. Suppose that in the same document we wanted to include another <title> tag to indicate a book title. How would a browser know that these two <title> tags are different? We would do that by enclosing the <title> tag for the book title within a unique namespace for a book -- say, for example <book xmlns="http://www.w3.org/1998/Book/BookML">. That way we would provide the browser the context for the two different <title> tags. That's it! That's what the namespaces are for: to provide the necessary context for the browser to avoic conflicts that could be caused by having the same tag names for different purposes. Writing XHTML: Discipline is good!If you're like me, you'd like to get started on writing XHTML as soon as possible. So here it is. First, let me warn you. Because XHTML is an application of XML, you will have to be very disciplined about how you write your HTML. Long gone are days where one could forget an end tag and have their friendly browser correctly interprets it for them. Here are the syntactical rules that XHTML documents will need to follow: 1. All the element and attribute names must be in lower case.
This is not good news for many HTML authors, who are used to writing HTML tags in upper case to improve readability. This is also difficult for some of the WYSIWYG HTML editors, which produce HTML tags in uppercase. 2. All attribute values must be quoted
3. All tags must close (if it's an empty element, see 4 below)
4. Empty elements such as <hr> must have a trailing slash
If you notice, I've put a space before the trailing slash. Although this is not required in XHTML (or XML), it is important for backward compatibility with existing HTML browsers. I'll explain this a little later. 5. All elements must nest correctly and not overlap.
6. Minimized attributes must be stated as an attribute-value
pair.
7. Include DOCTYPE declaration for every document <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> You should use STRICT declaration when you're doing all of your formatting using Cascading Style Sheets (CSS). That is you aren't relying on <font> and <table> tags to control the presentation and layout of your page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> You should use TRANSITIONAL declaration when you're NOT doing all of your formatting using Cascading Style Sheets (CSS). Most of us don't because we don't want users with non-CSS browsers to have a compromised experience. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd"> The FRAMESET declaration is used when you're using FRAMES. 8. All scripts and style declarations must be in CDATA elements
Making XHTML Compatible with Existing BrowsersAlthough most current crop of browsers do not support XHTML, it doesn't mean that we can't start writing HTML. If you start taking some care in how you write HTML now, you'll be closer to compatibility with XHTML when the browsers do start supporting it and requiring XHTML from Web authors. Some of these compatibility guidelines are listed below:
Testing Correctness of XHTML SyntaxUndoubtedly, we will make mistakes when creating XHTML-compatible documents. And it wouldn't be a very satisfying job in the world to figure out where we messed up in our syntax. Until HTML editors catch up with this, consider using HTML Tidy developed by Dave Raggett. It's downloadable for free at http://www.w3.org/People/Raggett/tidy/ Just to get used to writing XHTML, I tried to follow XHTML conventions on this page. If you're interested in knowing how different this page looks, view source of this document and you will get the idea. For your information, I did run HTML Tidy program built-in Allaire HomeSite 4.5.1 to make sure that I did it right. Interestingly, it generated 5 errors. All the errors were caused because I did not includee the summary attribute in my table tag. And here's the reason it gave: The table summary attribute should be used to describe the table structure. It is very helpful for people using non-visual browsers. The scope and headers attributes for table cells are useful for specifying which headers apply to each table cell, enabling non-visual browsers to provide a meaningful context for each cell. Very cool! What else is new with XHTML?One of the important extension to the basic HTML form elements, is called FML or XForms. Perhaps, I'd explain that in one of the upcoming workshops. In the meantime, if you are interested in learning more about them, visit W3C page on XForms at http://www.w3.org/MarkUp/Forms/. If you have any questions or suggestions about these workshops, feel free to send me an e-mail at pvora@mindspring.com. References
© Internet Technical Group Last update: April 30, 2000 URL: http://www.sandia.gov/itg/newsletter/mar00/workshop_xhtml.html hosted by Sandia National Labs Disclaimer: Neither Sandia Corporation, the United States Government, nor any agency thereof, nor any of their employees makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately-owned rights. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by Sandia Corporation, the United States Government, or any agency thereof. The views and opinions expressed herein do not necessarily state or reflect those of Sandia Corporation, the United States Government or any agency thereof. |