- From: Leif Halvard Silli <xn--mlform-iua@xn--mlform-iua.no>
- Date: Wed, 10 Mar 2010 04:48:35 +0100
- To: "Jukka K. Korpela" <jkorpela@cs.tut.fi>
- Cc: Claudia Murialdo <cmurialdo@gmail.com>, www-validator@w3.org
I keep coming back to Claudia's question ... > Claudia Murialdo wrote: >> I need to add a few custom attributes in some HTML elements, which is >> the best way to do it in order to keep validating with w3c validation >> service?. ... and to Jukka's answer (internal subsets). And to his regret ... Jukka K. Korpela, Fri, 12 Feb 2010 06:17:49 +0200: > […] now I vaguely remember why I haven't used this nicer approach […] > The problem here is that browsers don't even _parse_ DOCTYPE > declarations properly: they'll take "] >" as document content and > display them at the start of the page. This happens even in IE 8 and > Firefox 3.5, so it won't ever change. [...] To solve the parsing issue for HTML4 pages, I've already shown a HTML4 syntax compatible solution which gets parsed without the "]>" in the body. [1] But a XHTML syntax compatible solution for text/html parsers seemed impossible. Until I learned that processing instructions (PIs) are allowed inside the internal subset, which made the solution even simpler than the HTML4 solution: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST html class CDATA #IMPLIED> <?parser-hack ><!--?> ]> <!--><?!--> Explanation of how it works, for the interested: The "<?parser-hack" line is an XHTML PI, and it is thus terminated by the "?>". However, Web (text/html) parsers still parse it as an HTML4 PI, thinking that it is terminated by the first ">". This allows us to fool the text/html parsers in a cross browser compatible way by sticking inside the PI a ">" followed by the beginning of an HTML, which we in turn place before the "]>". The last, funny looking comment line catches and "breaks up" the comment that most browsers perceived as starting inside the PI and MUST/SHOULD - by and large - look exactly like above, in order to be cross browser compatible. I also tested serving the above as "application/xhtml+xml". It worked flawlessly in Opera and Firefox. But Webkit apparently had a parsing bug which were causing "yellow screen of death". Seems like Webkit's XML parser applies text/html parsing inside the DTD ... (It works without a hitch if you place the same PI anywhere inside the body of the document.) [1] http://målform.no/html4-or-html5/take2_workaround -- leif halvard silli
Received on Wednesday, 10 March 2010 03:49:13 UTC