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

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

From: David Dorward <david@dorward.me.uk>
Date: Mon, 1 Feb 2010 10:51:16 +0000
Cc: www-validator@w3.org
Message-Id: <995F6E43-D089-4205-A432-150C4081CE42@dorward.me.uk>
To: Leif Halvard Silli <xn--mlform-iua@xn--mlform-iua.no>

On 1 Feb 2010, at 10:03, Leif Halvard Silli wrote:
>> Since <script> elements are defined as containing CDATA, I assume the 
>> <![CDATA marker is (supposed to be) treated as character data and not 
>> markup. The </ of </bb> is then considered to be an end tag which 
>> fails to match the opening <script> tag.
> So you say that placing "<![CDATA[" there is i valid, but without 
> effect on the escaping needs ... 

As far as I can tell, it should be treated as any other character data. 

i.e. passed to the JS engine where the prefixing // causes it to be handled as an single line comment

> 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>).

> 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).

> 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.

  Line 6, Column 30: end tag for element "DIV" which is not open

The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

If this error occurred in a script section of your document, you should probably read this FAQ entry.

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)

David Dorward
Received on Monday, 1 February 2010 10:51:50 UTC

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