Where has XHTML gone?
Where has XHTML gone?
Join the DZone community and get the full member experience.Join For Free
Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.
When I started working in the web development field, XHTML had recently been introduced and was all the rage. I even included XHTML templates and a copy of the DTD in our enterprise CMS, believing that in some years the publicly hosted DTD would be targeted by millions of users browsers, trying to validate XHTML code and rejecting malformed documents.
But now in 2011, where XHTML has gone?
What XHTML is
XHTML is a specification which defines the XML serialization of HTML: while HTML itself is not a strict language, and ignore most of the malformed tags and nesting structures, XML is much more draconian. In its original versions, XHTML 1 and 2, XHTML was the reformulation of HTML 4 in order to transform HTML documents in valid XML ones, agnostic with respect to the graphic presentation or the media type.
For example, XHTML deprecated or invalidated all tags strictly related to presentation issues, like <b> (substituted by <strong>) but also <font>. Ideally, XHTML documents could just be viewed on different medias by specifying a different CSS.
An interesting idea of XHTML was also providing different modules, via XML namespaces. You are able to compose different markup languages in a document, in addition to the standard one: a language for forms, one for mathematical formulas, one for vector graphics.
Here's an example of XHTML snippet, including a MathML expression.
<p>Some random text.</p>
A bit verbose, but comparing to using cryptic LaTeX notation, which must be parsed on the server-side, it's not so ugly.
Another advantage of XHTML may be the use of XML tools for web pages too: in every language you have an XML parser, but an HTML one is more difficult to find or write.
XHTML 1.0 dates back to 2000. If it is so powerful, why it has not been widely adopted?
I think here's why:
XML has a very strict syntax with respect to SGML-derived languages like HTML. If there is a syntax error or a missing closing tag or attribute double quote in even one row of your XHTML document, it won't be interpreted by the browser.
The Facebook case
Facebook includes an XHTML 1.0 strict doctype in each page. However, it serves documents with the text/html HTTP response header, which means browser do not treat the content as XML.
For example, the following snippet produces a friend selector, of course customized for the current user:
<form action="http://www.example.com/handler.php" id="testForm" method="post">
<fb:friend-selector uid="12345" name="uid" idname="grab_me_please" prefill_id="7906796"/>
<input type="submit" value="test" />
Rather then resorting to custom attributes over standard tags like many JS frameworks do, this declarative approach adds a fb XHTML namespace and makes available a whole new set of tags with extended capabilities. And it uses a well-documented standard, like XHTML.
Just when you thought XHTML may disappear, I have to tell you that XHTML has been evolved to accomodate the HTML 5 specification. You can write (only if you really want, of course) HTML 5 as valid XML. However it seems that XHTML 5 will try to remain backward compatible with HTML, for example by allowing elements like <i> and <font> in certain use cases.
As a web developer, will you use XHTML  in the future?
http://www.w3.org/MarkUp/2004/xhtml-faq#advantages admits that translating an HTML document in XHTML won't result in a difference, unless you incude other languages.
Wikipedia's article on MathML shows you an example of a language that can be used in an XHTML document as a module.
Opinions expressed by DZone contributors are their own.