Re: problem validation


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[ .. ]]>,

<script type="text/javascript"><![CDATA[
   for (i=3; i<= <?=$_SESSION['posturi']['nr_raspunsuri']; ?>; i++)

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.


Benjamin Niemann
Email: pink at odahoda dot de

Received on Tuesday, 31 July 2007 12:38:35 UTC