6

Saw this question: At the end of the day, why choose XHTML over HTML?

But all the answers are from 2009. From the dead XHTML 2.0 and now XHTML5, what's the current consensus? Is there any real reason to use (or not to use) XHTML these days?

skippr
  • 2,656
  • 3
  • 24
  • 39

1 Answers1

7

The question is not about HTML versus XHTML, the question is about the HTML parser versus the XML parser.

Presuming you've served a page with the XHTML header the media type / mime is application/xhtml+xml. The only notable browser version that does not support XHTML is Internet Explorer 8 however if you're reading this in 2017 or later (this being posted October 2017) even IE11 is minimally relevant. So browser support is no longer a consideration. Internet Explorer 5 does technically have an XML parser though it only recognizes the application/xml media type / mime.

Once you get past the browser support the correct question to ask is: what is the difference between the HTML parser and the XML parser? I've meet developers who make six figures and have no idea what an XML parser is. A parser in general takes code and creates a data structure; in both cases the DOM (Document Object Model). If both produce the same DOM then why the difference and why does it matter?

The XML parser is strict. If you lived in an "XML community" you must cut your grass once every two weeks, you have to have the trash buckets in before 6pm, you can't have inoperable cars even in your garage and neighborhood grannies routinely patrol the streets for any punk teenagers who dare stop to loiter for even several seconds.

The HTML parser is not strict. If you lived in the "HTML community" you're allowed to have your lawn resemble the Amazon rain forest, have piles of trash collecting for months at a time by the curb, inoperable cars are parked half on the lawn and half in your living room and mobs of drunk hobos roam the neighborhood in droves.

Of course there are plenty of websites built using standards compliant HTML however the vast majority of text/html websites are of middling to low quality. Attributes that don't have values and entities that aren't encoded or improperly encoded are a couple of easy examples.

If you're aiming for the best that can be had you'll want to code using XHTML5. To be specific: you'll use HTML5 rendered with the XML parser. Gecko (Firefox / Waterfox) will break the entire page and give you an error message. Some people really dislike that however I love it. If you're not aware of the issue there is no expectation that you'll fix it. Other engines (Presto / (real) Opera, Blink / Chrome, WebKit / Safari) will render up to the parse error.

There will always be naysayers who have psychologically decided to ignore objectivity and blindly believe doing what everyone else they know is doing is inherently superior because egotism is more important than objectivity. However if you're not stuck on such false notions and want to improve your capability to program, recover from errors faster and become aware of concepts that most aren't that will grant you advantages most other designers/developers don't have I recommend using the XML parser and coding as strictly as you can. A computer can only help you produce at the level you decide to produce at.

John
  • 1
  • 13
  • 98
  • 177