Polyglot XHTML: Serving pages that are valid HTML and valid XML at the same time.
A number of documents have been written on the subject, which I shall not repeat here.
- HTML5 is not going away.
- XHTML pages validate in the browser.
- If you can get better validation during the development of your website, then you’ll save yourself time and headaches.
- Thus, for your development environment, you’ll set the equivalent of
DEFAULT_CONTENT_TYPE = 'application/xhtml+xml'(and a workaround for Django pages if they’re out of your control)
- But for your production environment, you’ll still use
- Even though your page is served as html, you can still use XML parsers to do processing on it.
Apparently, the W3C resource about polyglot XHTML has been taken out of maintenance, without an explanation. I figure they figured it’s not worth the efforts, as the whatwg wiki states: “You have to be really careful for this to work, and it’s almost certainly not worth it. You’d be better off just using an HTML-to-XML parser.”
I think that’s an exaggeration. Jesper Tverskov wrote an excellent article called Benefits of polyglot XHTML5 where he summarized how little work it is.
For convenience, I’ve copied the “polyglot in a nutshell” here:
If you are new to polyglot XHTML, it might seem quite a challenge. But if your document is already valid HTML5, well-formed, and uses lower-case for element and attribute names, you are pretty close. The following 10 points almost cover all of polyglot XHTML:
- Declare namespaces explicitly.
- Use both the
colelement is used in tables, also use
- Don’t use
- Don’t start
textareaelements with newline.
innerHTMLproperty instead of
- Many names in SVG and one in MathML use lowerCamelCase.
The following additional rules will be picked up by HTML5 validation if violated:
- Don’t use XML Declaration or processing instructions. Don’t use xml:space and xml:base except in SVG and MathML.
- Elements that can have content must not be minimized to a single tag element. That is
<br/>is ok but
<p></p>must be used instead of
Back to overview Newer post: salt master losing children Older post: Availability during holiday december 2015