DOMCDATASection (JavaScript)

Represents a CDATA section.

Defined in

DOM (JavaScript)

Methods

This class inherits the methods of DOMNode (JavaScript), DOMCharacterData (JavaScript), and DOMText (JavaScript).

Usage

A CDATA section treats its data content as plain text not recognizing any markup except ]]>. Contrast with DOMText (JavaScript).

CDATA sections cannot be nested.

Examples

(1) This button creates a document with a hierarchy of elements where the last element contains a CDATA section.
var doc = database.createNewDocument();
var dom = doc.getDOM();
var schema0 = dom.createElement("schema0");
var element0 = dom.createElement("element0");
var cdata0 = dom.createCDATASection(requestScope.s);
dom.appendChild(schema0);
schema0.appendChild(element0);
element0.appendChild(cdata0);
doc.save()
The XML for this document appears follows if requestScope.s is <foo>:
<schema0>
  <element0><![CDATA[<foo>]]></element0>
</schema0>
(2) This example is the same as the previous but uses a DOMCharacterData method to set the data value:
var doc = database.createNewDocument();
var dom = doc.getDOM();
var schema0 = dom.createElement("schema0");
var element0 = dom.createElement("element0");
var cdata0 = dom.createCDATASection(null);
dom.appendChild(schema0);
schema0.appendChild(element0);
element0.appendChild(cdata0);
cdata0.setData(requestScope.s);
doc.save()