Easy Tutorial
❮ Dom Prop Attr Value Dom Errors Crossbrowser ❯

XML DOM createCDATASection() Method



Definition and Usage

The createCDATASection() method creates a CDATA section node.

This method returns a CDATASection object.

Syntax

Parameter Description
data A string that specifies the data for the node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and adds a CDATA section node to the <book> element:

Example

xmlDoc = loadXMLDoc("books.xml");

x = xmlDoc.getElementsByTagName("book");

newtext = "Special Offer & Book Sale";

for (i = 0; i < x.length; i++) {
  newCDATA = xmlDoc.createCDATASection(newtext);
  x[i].appendChild(newCDATA);
}

for (i = 0; i < x.length; i++) {
  document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
  document.write(" - ");
  document.write(x[i].lastChild.nodeValue);
  document.write("<br>");
}

❮ Dom Prop Attr Value Dom Errors Crossbrowser ❯