DOMText (JavaScript)

Represents the content (character data) of an element or attribute.

Defined in

DOM (JavaScript)

Methods

This class inherits the methods of DOMNode (JavaScript) and DOMCharacterData (JavaScript). Other methods are in addition.

Usage

Text nodes recognize XML markup. Methods that set data for text nodes convert markup to entity references. The following entity references are predefined:
Markup Entity reference
< (less than) &lt;
> (greater than) &gt;
& (ampersand) &amp;
' (apostrophe) &apos;
" (quotation mark) &quot;

Examples

(1) This button creates a document with a hierarchy of elements where the last element contains a text node.
var doc = database.createNewDocument();
var dom = doc.getDOM();
var schema0 = dom.createElement("schema0");
var element0 = dom.createElement("element0");
var text0 = dom.createTextNode(requestScope.s);
dom.appendChild(schema0);
schema0.appendChild(element0);
element0.appendChild(text0);
doc.save()
The XML for this document appears as follows if requestScope.s is <foo>:
<schema0>
  <element0><![CDATA[<foo>]]></element0>
</schema0>
If requestScope.s is <foo>, the XML appears as follows:
<schema0>
  <element0>&lt;foo&gt;</element0>
</schema0>
(2) This example is the same as above 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 text0 = dom.createTextNode(null);
dom.appendChild(schema0);
schema0.appendChild(element0);
element0.appendChild(text0);
text0.setData(requestScope.s);
doc.save()