Re: SCRIPT and embedded markup

On Mon, 30 May 2005 wrote:

> But the reason for there being even a mention to the invalidity of the
> following is astounding (from
> <>:
> <script type="text/javascript">
> <!--
>   // This is an error!
>   document.write("</P>");
> // -->
> </script>
> The purpose of commenting out the script content is to hide it from old
> (really old) browsers so that only newer browsers handle it. However,
> just because UAs stoop to the level of snooping out comments to support
> an outdated and improper hack does not mean a validator should.
> As far as a validator that *properly* parses HTML or XML documents, the
> above code should be exactly identical to the following:
> <script type="text/javascript">
> </script>

That's true in XHTML but not in HTML.  In HTML 4, the "script" element is
declared as having CDATA content, whereas XHTML declares "script" to have
#PCDATA content.

In CDATA content, the "<!--" and "-->" are part of the script; they are
not HTML comments.  In CDATA content, end tags are recognized, but start
tags and comments are not.  That's not intuitive, but that's how CDATA is
defined in SGML and hence HTML.

Liam Quinn

Received on Wednesday, 1 June 2005 00:36:52 UTC