Special Characters and CDATA
Special Characters and CDATA
In XHTML the < and & are special characters that the XML processor will interpret as the start of markup. You’ll usually find these characters in Javascript such as this simple if statement:
<script type="text/javascript">
if (5 < 10) {
document.write(Way to go!’);
}
</script>
Another common place that you’ll find special characters are links with parameters like this:
<a href="http://yoursite.com/index.html?id=1234&name=bob"
title="Link to Bob" />
Both of these examples would fail in an XHTML validator. In order to use these special characters you must either use the specific character entity or escape the whole block of code using the CDATA delimiter. CDATA should always be used within script and style elements that are embedded in the page:
<script type="text/javascript">
<![CDATA[
if (5 < 10) {
document.write(Way to go!’);
}
]]>
</script>
<style type="text/css">
<![CDATA[
body {font-family:arial,sans-serif}
]]>
</style>
When the special characters < and & are not contained within a script or style element and do not indicate the start of markup you should use the < and & character entities respectively.









