Class Cdata

Cdata

XML CDATASection 节点的表示形式。

// 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);

方法

方法返回类型简介
append(text)Text将指定文本附加到节点中已有的任何内容。
detach()Content|null将节点从其父级 Element 节点分离。
getParentElement()Element|null获取节点的父 Element 节点。
getText()String获取 Text 节点的文本值。
getValue()String按节点在文档中出现的顺序获取该节点的所有直属或非直属子节点的文本值。
setText(text)Text设置 Text 节点的文本值。

详细文档

append(text)

将指定文本附加到节点中已有的任何内容。

参数

名称类型说明
textString要附加到节点的文本。

返回

Text - Text 节点,用于链式调用。


detach()

将节点从其父级 Element 节点分离。如果节点没有父节点,此方法不起作用。

返回

Content|null - 分离的节点。


getParentElement()

获取节点的父 Element 节点。如果节点没有父级,此方法会返回 null

返回

Element|null - 父级 Element 节点。


getText()

获取 Text 节点的文本值。

返回

String - Text 节点的文本值。


getValue()

按节点在文档中出现的顺序获取该节点的所有直属或非直属子节点的文本值。

返回

String - 相应节点的所有直接或间接子节点的文本值。


setText(text)

设置 Text 节点的文本值。

参数

名称类型说明
textString要设置的文本值。

返回

Text - Text 节点,用于链式调用。