Welcome Login

Cdata Sections


CDATA  Sections are used to escape a whole block of text.

The XML processor knows to escape all data between the CDATA tags.

You declare a CDATA section using <![CDATA[ as the opening tag, and ]]> as the closing tag.

Compare with entity reference, escaping a single character.



Text you want to escape goes here...



Cdata in Program output:

Since it is useful to be able to use less-than signs (<) and ampersands (&) in web page scripts, and to a lesser extent styles, without having to remember to escape them, it is common to use CDATA markers around the text of inline <script> and <style> elements in XHTML documents. But so that the document can also be parsed by HTML parsers, which do not recognise the CDATA markers, the CDATA markers are usually commented-out.

Eg: cdata in script output.  CDATA markers are usually commented-out in js.

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

function printAlert {
alert("hello world!");

// ]]>


Eg2: in css. Here too, cdata markers are commented out.

<style type="text/css">

body { background-image: url("marble.png?width=300&height=300") }


Created on: Wednesday, April 20, 2011 by Andrew Sin