AI-generated Key Takeaways
-
Cdata
represents an XMLCDATASection
node, allowing you to store special characters like '<', '>', and '&' literally without escaping them. -
It provides methods to manipulate the CDATA content, such as appending text, detaching from the parent element, and retrieving or setting the text value.
-
You can create a
Cdata
node usingXmlService.createCdata(text)
and incorporate it into your XML document. -
Cdata
is particularly useful when dealing with data that contains characters that would otherwise be interpreted as XML markup. -
It offers flexibility in managing the CDATA content within the XML structure through various methods like
append
,detach
,getText
,getValue
, andsetText
.
A representation of an XML CDATASection
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. const illegalCharacters = '<em>The Amazing Adventures of Kavalier & Clay</em>'; const cdata = XmlService.createCdata(illegalCharacters); const text = XmlService.createText(illegalCharacters); const root = XmlService.createElement('root').addContent(cdata).addContent(text); const document = XmlService.createDocument(root); const xml = XmlService.getPrettyFormat().format(document); Logger.log(xml);
Methods
Method | Return type | Brief description |
---|---|---|
append(text) | Text | Appends the given text to any content that already exists in the node. |
detach() | Content | Detaches the node from its parent Element node. |
get | Element | Gets the node's parent Element node. |
get | String | Gets the text value of the Text node. |
get | String | Gets the text value of all nodes that are direct or indirect children of the node, in the order they appear in the document. |
set | Text | Sets the text value of the Text node. |
Detailed documentation
append(text)
Appends the given text to any content that already exists in the node.
Parameters
Name | Type | Description |
---|---|---|
text | String | the text to append to the node |
Return
Text
— the Text
node, for chaining
detach()
getParentElement()
getText()
Gets the text value of the Text
node.
Return
String
— the text value of the Text
node
getValue()
Gets the text value of all nodes that are direct or indirect children of the node, in the order they 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 the Text
node.
Parameters
Name | Type | Description |
---|---|---|
text | String | the text value to set |
Return
Text
— the Text
node, for chaining