Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.