[Javascript] Decrement operator, XHTML Strict 1.1 DTD, Internet Explorer 6?

Nick Fitzsimons nick at nickfitz.co.uk
Sun Jul 30 07:32:35 CDT 2006


John Warner wrote:
> 
> Target browser is IE 6 (Winders)
> This is for my own education, how do you handle this? I was trying to 
> use the XHTML 1.1 Strict DTD. With my script code in the document head, 
> I have a function that has a line of code:
> --counter  //decrement counter
> The code works this way just fine in IE. But when I went to the w3c 
> validator it fails me due to this line within my script; calls it an 
> improperly formed comment. OK, I think and proceed to enclose my script 
> code within a CDATA block. W3C validator says OK, script blows up in IE 
> - wait for it, guess where, on the CData opener and closer. So is it 
> possible to use the decrement operator in a script with the Strict 1.1 
> dtd and IE 6? If so what have I missed and other then the obvious
> counter = counter -1;
> Is there a solution for this? Note telling me Firefox or Opera etc is 
> useless the target is IE.
>  

As David Dorward has pointed out, XHTML 1.1 can only be served as XML; 
however IE 6 cannot process the MIME type application/xml+xhtml, so it 
cannot process XHTML 1.1. In fact, IE cannot process XHTML at all; the 
only way it handles XHTML 1.0 is by treating it as if it is malformed 
HTML 4.

As XHTML is an XML vocabulary, you are required to comply with the whole 
of the XML standard, which states:

"For compatibility, the string "--" (double-hyphen) MUST NOT occur 
within comments."
<http://www.w3.org/TR/REC-xml/#sec-comments>

As the only reason for wrapping scripts in HTML comments is to play nice 
with browsers that nobody has used since about 1998, you don't need to 
do it anymore. The correct mechanism for preventing XHTML parsers from 
getting upset by the content of scripts (eg "a < b") is, as you tried, 
CDATA sections. However, as Internet Explorer's HTML parser doesn't know 
what they are, it doesn't work and causes an error.

As IE 6 is your target browser, use HTML 4.01 Strict. IE 7 won't support 
XHTML either (Chris Wilson, lead program manager for IE and all-round 
nice guy, explains why at 
<http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx>), so for your 
purposes, you should regard XHTML as a nice technology that you are 
prevented from using by lack of support in your target platform, and 
will not be able to use on newer versions of that platform for 
(probably) a year or so.

HTH,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list