Jump to content

cdata sections and xhtml doctypes


sKunKbad

Recommended Posts

Is there any real value to declaring CDATA sections like this:

 

<script type="text/javascript">
     //<![CDATA[
          document.cookie = "js-enabled=yes"; 
     //]]>
</script>

 

and here:

 

<style type="text/css" media="screen">
     /*<![CDATA[*/
          * { margin:0px; padding:0px; font-family:Verdana, Arial, Helvetica, sans-serif; }
     /*]]>*/
</style>

 

I've never heard of a browser having a problem with a document that didn't have the character data wrapped in CDATA section markers, and it doesn't do anything for validation, so what's the deal?

Link to comment
https://forums.phpfreaks.com/topic/79514-cdata-sections-and-xhtml-doctypes/
Share on other sites

CDATA is data which, by an XML parser, is supposed to be interpreted as character instead of markup.

E.g.

<![CDATA[<sender>John Smith</sender>]]>

should be interpreted as had it been written like this:

<sender>John Smith</sender>

 

Similarly,

<![CDATA[©]]>

should be interpreted as an ampersand followed by copy followed by a semi-colon (i.e. what is literally written) while

©

should be interpreted as the character ©.

 

That is the purpose of CDATA. It's a way of ensuring that content between e.g. <script> tags won't be interpreted as markup and therefore "ignored" by the parser.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.