XHTML reformulates the existing HTML technology to be an application of XML. It is already used for mobile phone and PDA Internet sites, and expected to gain widespread use as XML becomes more popular. Dan Wellman explains the differences between XHTML and HTML 4, and shows how easy it is to make the switch.
An Introduction to XHTML - Namespace awareness (Page 5 of 5 )
In keeping with XML, XHTML is also namespace aware and in both 1.0 and 1.1 XHTML specifications, the root or html element must contain the following namespace URL:
Additional namespaces can be declared in any child or grandchild and subsequent elements of the root element in the same way. For the more simple XHTML documents, this should not be necessary, but when you get to the stage where you are adding your own XHTML elements (the X still stands for eXstensible after all!), declaring additional namespaces and their associated prefix becomes increasingly necessary. It is through this technique that two of the same elements that mean different things can be used in the same document.
For example, your XHTML document must include a body element, but what if you want to produce a page containing numerous articles, each with a <headline> and <body> element? You could simply associate the prefix dxml (Dans XML) with your own unique namespace directly after the mandatory namespace declaration of the root element:
Then use the body element of your articles with the assigned prefix:
<dxml:body>This is the body of an article</dxml:body>
When creating XHTML documents, you have to save them with a HTM extension (that is at least the common practice), therefore what you're really saving are normal HTML documents, and any elements that are not correctly formed will still work. An excellent way of testing your XHTML documents for well-formedness is to save them as XML documents instead. To illustrate what I mean, type the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHMTL 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Example Strict XHMTL Document</title> </head> <body> <h1>An example Strict XHTML Document</h1> <p><font face="arial">The font tag is deprecated in XHTML Strict and XHTML 1.1</p> </body> </html>
Save the file with an HTM extension and load the page in a browser, it will work perfectly. But save the above code with an XML extension and try and load it in a browser. You will get a message advising "End tag 'p' does not match the start tag 'font'." Add the closing font tag (in the correct nesting order of course) and the document should display normally. This will not vet your documents for deprecated tags, but it should catch any syntactical errors.
As I've stressed throughout this article, XHTML is really easy if you've worked with HTML and pretty easy even if you haven't. I've tried to cover the basic building blocks of the language, but don't be fooled, there is far more that you can do with it than I have space to describe here. XHTML is the way of the future, use it! What more can I say?
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.