Log in

View Full Version : w3c validation enigma--xhtml



marain
04-22-2012, 01:54 PM
The w3c validation tool (http://validator.w3.org/) requires that various characters within xhtml be escaped. For example, "&"must be coded as "&amp;" and "<" must be coded as "&lt;". So far so good.

My question relates to the situation where these characters are contained within a javascript script. I think it is clear that the escaped coding is NOT to be used within scripts. After all, w3c is not intended to validate script content. And the script processors do not know how to process escaped characters. Thus, in http://www.marainlaw.com/page.php?here=index, the validator disregards the ">" characters in its morning/afternoon/evening script. So far, so good.

What is puzzling me is that on a different page that I am trying to develop, the validator is spitting out error messages concerning characters within a script that, were those not within a script, would have to be escaped. The errant page is http://www.marainlaw.com/page.php?here=test.

What am I missing?

A.

jscheuer1
04-22-2012, 03:24 PM
The solution is to either make the script external or to escape the entire script with not character data tags, example:


<script type="text/javascript">
/* <![CDATA[ */

/**********************************************************************************
*
* Left-Right Stripy Curtain Script- copyright Dynamic Drive (www.dynamicdrive.com)
* Adapted from http://www.dynamicdrive.com/dynamicindex3/document3.htm
* For full source code, 100s more free DHTML scripts, and TOS,
* visit http://www.dynamicdrive.com
*
**********************************************************************************/

var ns4=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0

var speed=20
var temp=new Array()
var . . .


. . . nterval(stopit)
}
}
}
function gogo(){
stopit=setInterval("openit()",100)
}
gogo()
/* ]]> */
</script>

marain
04-22-2012, 06:10 PM
John,

Firstly, I appreciate your time in replying to my messages.

That said, I remain puzzled why the validator appears to (correctly) ignore the unescaped ">"s in marainlaw.com/page.php?here=index.

A.

jscheuer1
04-22-2012, 07:10 PM
I think they are escaped, just not correctly. The standard for XHTML is the not character data escape I just outlined for you. I believe that script uses the HTML comment escape:


<script type="text/javascript">
<!--
script code here
// -->
</script>

Browsers are allowed to ignore that script completely, though few if any currently do.