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

Re: problem validation

From: Benjamin Niemann <pink@odahoda.de>
Date: Tue, 31 Jul 2007 14:38:01 +0200
To: www-validator@w3.org
Message-ID: <f8naf9$u8f$1@sea.gmane.org>

Hello,

mihai puscasu wrote:

> I find a problem that occurred with the java script codes.
> 
> this is the javascript code:
> 
> <script type="text/javascript">
>         for (i=3; i<= <?=$_SESSION['posturi']['nr_raspunsuri']; ?>; i++)
>         {
>           document.getElementById("n_"+i).style.display="";
>         }
>       </script>
> 
> at the validation i get this error which is not actually an error:
> 
> 
>    1. [image: Error] *Line 51, Column 16*: XML Parsing Error: StartTag:
>    invalid element name.
> 
>        for (i=3; i<*=*nr; i++)
> 
>    2. [image: Error] *Line 53, Column 19*: XML Parsing Error: StartTag:
>    invalid element name.
> 
>        for (k=++nr; k<*=*10; k++)
> 
> 
> 
> i think you should do something with scripts between <script
> type="text/javascript">
> this is an annoying error which is not an error!

You have not provided a URL to the document in question, or stated that you
use XHTML, but the error messages point to the latter.
In XHTML *any* '<' (and '&') must be escaped, unless it appears in a CDATA
marked section or comment declaration.
The reported errors are indeed real errors. It may work (as in 'gives the
intended result') in all browsers you have used for testing. But this does
not make it correct.

If you really need embedded scripts and you can't use the preferred method
of references an external script, wrap your script in <![CDATA[ .. ]]>,
i.e.

<script type="text/javascript"><![CDATA[
   for (i=3; i<= <?=$_SESSION['posturi']['nr_raspunsuri']; ?>; i++)
   {
      document.getElementById("n_"+i).style.display="";
   }
]]></script>

Be aware of the fact that the often seen <script ..><!-- ... --></script>
does indeed silence the validator, but also hides the script from
user-agents that use real XML parsers.


HTH

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
Received on Tuesday, 31 July 2007 12:38:35 GMT

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