Class Cdata

  • The Cdata object represents an XMLCDATASection node.

  • Special characters are stored differently inCDATASection nodes compared to Text nodes.

  • Methods are available to manipulate Cdata nodes, such as appending text, detaching from a parent, getting the parent element, and getting or setting the text value.

Cdata

A representation of an XMLCDATASection node.

// Create and log an XML document that shows how special characters like '<',// '>', and '&' are stored in a CDATASection node as compared to in a Text node.constillegalCharacters='<em>The Amazing Adventures of Kavalier & Clay</em>';constcdata=XmlService.createCdata(illegalCharacters);consttext=XmlService.createText(illegalCharacters);constroot=XmlService.createElement('root').addContent(cdata).addContent(text);constdocument=XmlService.createDocument(root);constxml=XmlService.getPrettyFormat().format(document);Logger.log(xml);

Methods

MethodReturn typeBrief description
append(text)TextAppends the given text to any content that already exists in the node.
detach()ContentDetaches the node from its parentElement node.
getParentElement()ElementGets the node's parentElement node.
getText()StringGets the text value of theText node.
getValue()StringGets the text value of all nodes that are direct or indirect children of the node, in the orderthey appear in the document.
setText(text)TextSets the text value of theText node.

Detailed documentation

append(text)

Appends the given text to any content that already exists in the node.

Parameters

NameTypeDescription
textStringthe text to append to the node

Return

Text — theText node, for chaining


detach()

Detaches the node from its parentElement node. If the node does not have a parent,this method has no effect.

Return

Content — the detached node


getParentElement()

Gets the node's parentElement node. If the node does not have a parent, this methodreturnsnull.

Return

Element — the parentElement node


getText()

Gets the text value of theText node.

Return

String — the text value of theText node


getValue()

Gets the text value of all nodes that are direct or indirect children of the node, in the orderthey appear in the document.

Return

String — the text value of all nodes that are direct or indirect children of the node


setText(text)

Sets the text value of theText node.

Parameters

NameTypeDescription
textStringthe text value to set

Return

Text — theText node, for chaining

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.