XML DOM createCDATASection() Method

Document Object Reference Manual

Definition and Usage

The createCDATASection() method can create a CDATASection node.

This method can return a CDATASection object.

Syntax:

createCDATASection(data)
Parameter Description
data A string value, which can specify data for this node.

Return value

Returns the newly created CDATASection node, containing the specified data.

throw

If the document is an HTML document, this method will throw a NOT_SUPPORTED_ERR code DOMException Exception, because HTML documents do not support CDATASection nodes.

Example

In all examples, we will use the XML file books.xml, as well as the JavaScript function loadXMLDoc().

The following code snippet can add a CDATA section node to the <book> element:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newCDATA,newtext;
newtext="Special Offer & Book Sale";
for (i=0;i<x.length;i++)
  {
  newCDATA=xmlDoc.createCDATASection(newtext);;
  x[i].appendChild(newCDATA);
  }

Document Object Reference Manual