Document: createCDATASection() method

createCDATASection() creates a new CDATA section node, and returns it.

Syntax

js
createCDATASection(data)

Parameters

data

A string containing the data to be added to the CDATA Section.

Return value

A CDATA Section node.

Examples

js
const doc = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const cdata = doc.createCDATASection("Some <CDATA> data & then some");
doc.querySelector("xml").appendChild(cdata);
console.log(new XMLSerializer().serializeToString(doc));
// Displays: <xml><![CDATA[Some <CDATA> data & then some]]></xml>

Notes

Specifications