W3C home > Mailing lists > Public > www-validator@w3.org > September 2007

Re: [VE][79] and [VE][61] error in js section

From: David Dorward <david@dorward.me.uk>
Date: Tue, 18 Sep 2007 09:00:57 +0100
Message-Id: <9647CFBB-CDE8-4E92-85D2-862489FCEFAA@dorward.me.uk>
Cc: www-validator Community <www-validator@w3.org>
To: "Kate" <kate@microbytes.com>

On 17 Sep 2007, at 20:09, Kate wrote:
> One of the most frustrating things I find with the validator is that
> perfectly valid JavaScript causes errors.

Embedding one computer language inside another computer language is  
always troublesome, you have to

> Putting the JavaScript in a separate file works when the  
> information in the JavaScript is static BUT
> when the JavaScript is in part generated by the PHP code it becomes  
> a real
> problem. It is not always possible to avoid end tags in scripts as the
> reason for the JavaScript in some of my files is to output blocks  
> of HTML or
> XHTML code. The work around for this can be quite ugly with things  
> like
> "document.write('<p id="'+$newid'+'" style="color:#FF0000">' +
> $javascriptvar + '</'+'p>);"

Well...

(a) Best practise generally says "Don't use document.write", use DOM  
methods instead.
(b) I'm not aware of any current browser which supports  
document.write in XHTML mode (XHTML documents served as text/html are  
treated at HTML so don't count)
(c) The FAQ describes that situation, it is not hard to stick a "\"  
before the / in an end tag, or use CDATA markers (if you are  
insisting on using XHTML).

> I have often wondered why the validator is not ignoring all the  
> data between
> the opening <script type="text/javascript"> tag and the closing </ 
> script>
> tag?

Because the HTML and XHTML specifications require it to. The former  
because the parser has to recognise where the end of the script  
element exists (and there are a number of shorthand constructs in  
SGML which mean that </script> isn't the only thing that can end the  
tag), the latter because XML is significantly simpler then SGML and  
doesn't have any syntax in its DTDs which can say "The content of  
this element is not markup".

-- 
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/
Received on Tuesday, 18 September 2007 08:02:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:25 GMT