Reputation: 37
After reading extensively about HTML5 and XHTML5 and after reading this post: Are (non-void) self-closing tags valid in HTML5? , I have got a very simple question:
"Is there a reason why it would be good to serialise HTML5 as XML?"
I understand:
So the question is:
"In which case would it be good to follow very strict XML rules when doing an HTML5 page?"
Above all when it comes to things like
1) The void elements
<img src="asdsad.jpg" /> compared with <img src="asdsad.jpg">
<area> compared with <area />
<meta> comparted with <meta/>
2) Checked, download etc.. like
<input type="checkbox" name="vehicle" value="Car" checked> VS
<input type="checkbox" name="vehicle" value="Car" checked="checked" />
Should I just write following the HTML5 standard and implement as much common sense as possible (lower case, good nesting) or is there A GOOD REASON for a standard company website to be coded in XHTML5?
Upvotes: 3
Views: 600
Reputation: 46559
In addition to Alohci's excellent answer, let me run by your bullet points briefly...
I understand:
(..)
- that it's good practice to nest elements correctly, use lower case letters, quote attributes, close tags etc...
Quoting attributes is always a good idea, as well as having no errors, but the rest really doesn't matter. Sure, it's fashionable these days to write tags and attributes in lowercase, but that by itself doesn't make it good practice. Not that uppercase is better, but I'm just saying. By the way, tag names are stored by the browser in the DOM as uppercase in HTML.
- that HTML5 has no DTD while XHTML has got a DTD and an XML parse
Well, XHTML5 doesn't have a DTD. It does use the XML parser, and that means you can't use entity references such as
. If you want to use references with XHTML, use numerical references like  
or revert to an older version that has a DTD.
- that if I specify a page as XHTML5 (HTML5 doctype + XHTML schema) some browsers might not process the page for minor errors etc...
No browsers tolerate errors in XHTML these days. There used to be browsers that could treat XHTML as HTML, but those no longer exist.
Upvotes: 2
Reputation: 82976
I'd say it's mostly about errors. If you always write perfect HTML, it really doesn't matter which mime type+syntax pair you choose.
When a page might contain errors though, each syntax has alternative benefits
The regular HTML syntax (served as text/html) means using a parser that will try to make the best of your errors. Your content will get rendered somehow, and in many cases, in the way that you intended. However, when it doesn't, debugging it can be made more difficult by the surprising fix-ups that the parser can make.
With the XHTML syntax (served as application/xhtml+xml) the opposite is true. If you make a syntax error, the parser will just stop. In a browser, you'll see either an error message or just the content up to the point where the syntax error was detected. Other kinds of errors though, can be easier to debug because the XML parser won't monkey about with your elements trying to fix the mistake.
To give an example, suppose you have
<style> td { font-weight:bold } </style>
<table>
<tr>
<td>
<span>First</span>
</td>
<span>Second</span>
</tr>
</table>
That's an HTML content model error because the second span is not in a td element. But it's not an XHTML syntax error (i.e. it's XML well-formed), so the XML parser won't stop on it.
If you use HTML syntax & mime type, what you'll see in a browser is
Second
First
because the HTML parser will move the second span completely out of the table. In more complicated tables, it can be hard to work out how that order has come about.
If you use the XHTML syntax and mime type, what you'll see in a browser is
First Second
If you then wonder why "Second" isn't in bold, you can find the appropriate markup more easily because everything's displayed in the order it's placed in the markup.
Upvotes: 2
Reputation: 1656
Typically when using web technologies you want to use json, not xml. Json has the same serializing capabilities and uses less characters so it’s lighter.
Upvotes: -3