Re: parsing of scripts

At 02:32 PM 12/03/99 +0000, Chris Nappin wrote:
>
> However, I am having trouble getting my work validated. I am curious about 
>how the contents of script tags are delt with - this is the source of 
>failures for some of the pages I have been trying to get validated.
>
>An example url is:   http://www.afcea.org.uk/test/contents.html
>
>This is a contents frame, using heavy DHTML usage. The validator seems to 
>be complaining about the following type of code:
>
><script language="JavaScript" type="text/javascript">
><!--
>   document.write ('<some really long tag ');
>   document.write ('with lots of data></tag>');
>// -->
></script>

From <http://www.w3.org/TR/REC-html40/types.html#idx-CDATA-1>:

'Although the STYLE and SCRIPT elements use CDATA for their data model, for
these elements, CDATA must be handled differently by user agents. Markup
and entities must be treated as raw text and passed to the application as
is. The first occurrence of the character sequence "</" (end-tag open
delimiter) is treated as terminating the end of the element's content. In
valid documents, this would be the end tag for the element.'

So you need to escape your </tag>:

<script language="JavaScript" type="text/javascript">
<!--
   document.write ('<some really long tag ');
   document.write ('with lots of data><\/tag>');
// -->
</script>

-- 
Liam Quinn

Received on Friday, 12 March 1999 11:42:06 UTC