XML DOM createCDATASection()Methods


Document object

Definition and Usage

The createCDATASection() method creates a CDATA section node.

This method returns a CDATASection object.

Syntax

createCDATASection(data)

Parameter Description
data String, this string specifies data for the node.


Example

The following code snippet usesloadXMLDoc()put "books.xmlLoad it into xmlDoc and add the 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>"); }

Try it Yourself »

Document objectother extensions