W3C home > Mailing lists > Public > www-validator@w3.org > February 2010

Re: HTML4 + <script><![CDATA[ </ENDTAG> ]]></script>

From: Leif Halvard Silli <xn--mlform-iua@xn--mlform-iua.no>
Date: Mon, 1 Feb 2010 17:42:43 +0100
To: David Dorward <david@dorward.me.uk>
Cc: www-validator@w3.org
Message-ID: <20100201174243078972.cdb49971@xn--mlform-iua.no>
David Dorward, Mon, 1 Feb 2010 10:51:16 +0000:
> On 1 Feb 2010, at 10:03, Leif Halvard Silli wrote:

>> Or, why doesn't the compatibility guidelines mention that, for 
>> embedding, then one should use BOTH "\/" and "<![CDATA[ ...]]>" 
>> simultaneously?
> Because they are concerned with writing XHTML that is compatible with 
> HTML parsers, not writing code that is both valid XHTML and HTML 
> (which is impossible once you start dealing with XHTML self-closing 
> tag syntax in the <head>).

Well, the right hand should care a little bit about what the left hand 
is doing.

Why does the HTML4 validator care about theoretical SGML while the 
XHTML guidelines care about real text/HTML parsers, only? They should 
try to live up to the same standard/reality.

(It is sometimes said that having to wrap the script in <![CDATA[ ]]> 
is a reason to use external scripts [e.g. you said so!]. This thing is 
also been used as argument for saying that it is more difficult to 
embed javascript in XHTML than in HTML4. However, in reality, there is 
even more reason to place HTML4 scripts in external files, due the to 
issue with the \/ escaping.)
>> And, in addition, you should as well take care of the javascript 
>> interpreter - instead of recommending to not use HTML comments at all, 
>> like the guidelines does/do, I would recommend this:
>> <script type="text/javascript"><!---><![CDATA[
>> document.write('<abc>abc<\/abc>');
>> <!---->]]></script>
>> Because, the javascript interpreters doesn't require more than that 
>> line beings with a "<!--" in order accept that the first line is a 
>> comment. If the code also ends with a "-->", then it can as well be 
>> interpreted as a valid HTML comment.
> ... or you could just use a JS comment rather than depending on hacks 
> designed to avoid having Netscape 2 and friends render JS as text 
> (which would break if the script was placed in an external file).

I believe all user agents support this so called hack - so I wonder why 
it isn't upgraded from being considered hack. I suppose I will continue 
to us <!--->, as may be compatible with a wider range of scripting 
languages. (After all, most scripting languages for the web has some 
knowledge about the HTML syntax.)
>> OK, thanks David. Much appreciated. It would really be helpful if the 
>> HTML4 validator recommended escaping the "\/" instead of (only) telling 
>> us to use external script files.
> It does.

The validator? Yes. In in cryptic words - as you documented below.

> •  Line 6, Column 30: end tag for element "DIV" which is not open
>    document.write('<div></div>');
  [ snip ] 
> If this error occurred in a script section of your document, you 
> should probably read this FAQ entry.

Right. There is just a single, cryptic sentence about the entire issue.

>> From said FAQ entry:
> Authors should avoid using strings such as "</P>" in their embedded 
> scripts. In JavaScript, authors may use a backslash to prevent the 
> string from being parsed as markup:
> (Followed by an example)

You say that you quoted the FAQ. However, you did not quote the FAQ - 
you quoted the WDG page which the FAQ points to. The FAQ only says this:

The validator complains about something in my JavaScript!
Most probably, you should read the script section of WDG's excellent 
Common HTML Validation Problems document.

So the FAQ page is - or appears - so cocky that it cannot explain this 
in its own words.  The FAQ has a unnecessary gotcha attitude. The W3 
validator did not need to point to the FAQ - it could have explained 
this issue itself - and it could have pointed to HTML4 directly - 
<http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2.1>. Or at least 
the FAQ could have done so. And the validator could also have mentioned 
a word about the discrepancy between user agents and SGML requirements.

Btw, the WDG page is wrong when it says that "in XHTML, authors must 
_also_ take care when using start tags within a script element".  
Because, as we have discussed in this thread: in XHTML, as long as you 
wrap the script in <![CDATA[ ]], then you do in principle not _also_ 
have to use "\/" - except, of course for compatibility with HTML4.
leif halvard silli
Received on Monday, 1 February 2010 16:43:19 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 14:18:00 UTC