XHTML Validator Bug?

Discussion in 'HTML & Website Design' started by Gordaen, Aug 22, 2006.

  1. #1
    Is the validator at fault?

    I wrote a script that grabs quite a bit of data to pass as post data to a PHP script via ajax. When I tried to validate the page, I got all kinds of errors about ampersand entities. Obviously, replacing them with & will make the data request NOT work, so is this a fault with the validator (i.e. the document IS valid) or is there some other way I should be doing this?

    Here's a mini-example with GET:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Validator Test</title>
    <script type="text/javascript">
    
    var exampleGetString;
    exampleGetString = "?somedata=1";
    exampleGetString += "&failedvalidation=1";
    
    </script>
    </head>
    
    <body>
    </body>
    </html>
    HTML:
     
    Gordaen, Aug 22, 2006 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    It's kinda your fault. As xhtml, you need to declare the script to be cdata.
    
    <script type="text/javascript">
    //<![CDATA[
    var exampleGetString;
    exampleGetString = "?somedata=1";
    exampleGetString += "&failedvalidation=1";
    //]]>
    </script> 
    Code (markup):
    The browser doesn't care, because it's treating the doc as html, but the validator takes you at your word. Even if validating html, it's probably a good idea to enclose the script within comment tags. Not sure on the last, as I haven't written an html page in ages.

    cheers,

    gary
     
    kk5st, Aug 22, 2006 IP
  3. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah, thanks for the input Gary. I totally forgot about cdata :)
     
    Gordaen, Aug 23, 2006 IP