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 | String | 要附加到节点的文本 |
返回
Text
- Text
节点,用于链式调用
getText()
获取 Text
节点的文本值。
返回
String
- Text
节点的文本值
getValue()
获取节点的直接或间接子节点的所有文本值,按文档中显示的顺序。
返回
String
- 节点的直接或间接子节点的所有文本值
setText(text)
设置 Text
节点的文本值。
参数
返回
Text
- Text
节点,用于链式调用
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eCdata\u003c/code\u003e represents an XML \u003ccode\u003eCDATASection\u003c/code\u003e node, allowing you to store special characters like '<', '>', and '&' literally without escaping them.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to manipulate the CDATA content, such as appending text, detaching from the parent element, and retrieving or setting the text value.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a \u003ccode\u003eCdata\u003c/code\u003e node using \u003ccode\u003eXmlService.createCdata(text)\u003c/code\u003e and incorporate it into your XML document.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCdata\u003c/code\u003e is particularly useful when dealing with data that contains characters that would otherwise be interpreted as XML markup.\u003c/p\u003e\n"],["\u003cp\u003eIt offers flexibility in managing the CDATA content within the XML structure through various methods like \u003ccode\u003eappend\u003c/code\u003e, \u003ccode\u003edetach\u003c/code\u003e, \u003ccode\u003egetText\u003c/code\u003e, \u003ccode\u003egetValue\u003c/code\u003e, and \u003ccode\u003esetText\u003c/code\u003e.\u003c/p\u003e\n"]]],["The document describes an XML `CDATASection` node and its methods. Key actions include creating a `CDATASection` with special characters, contrasting it with a `Text` node, and logging the results. Methods allow appending text, detaching from a parent, getting the parent element, retrieving text value, accessing the value of child nodes, and setting text. These functions enable manipulation and retrieval of the `CDATASection` node's content and structure within an XML document.\n"],null,["# Class Cdata\n\nCdata\n\nA representation of an XML `CDATASection` node.\n\n```javascript\n// Create and log an XML document that shows how special characters like '\u003c',\n// '\u003e', and '&' are stored in a CDATASection node as compared to in a Text node.\nconst illegalCharacters = '\u003cem\u003eThe Amazing Adventures of Kavalier & Clay\u003c/em\u003e';\nconst cdata = XmlService.createCdata(illegalCharacters);\nconst text = XmlService.createText(illegalCharacters);\nconst root =\n XmlService.createElement('root').addContent(cdata).addContent(text);\nconst document = XmlService.createDocument(root);\nconst xml = XmlService.getPrettyFormat().format(document);\nLogger.log(xml);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------|-------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [append(text)](#append(String)) | [Text](/apps-script/reference/xml-service/text) | Appends the given text to any content that already exists in the node. |\n| [detach()](#detach()) | [Content](/apps-script/reference/xml-service/content) | Detaches the node from its parent [Element](/apps-script/reference/xml-service/element) node. |\n| [getParentElement()](#getParentElement()) | [Element](/apps-script/reference/xml-service/element) | Gets the node's parent [Element](/apps-script/reference/xml-service/element) node. |\n| [getText()](#getText()) | `String` | Gets the text value of the `Text` node. |\n| [getValue()](#getValue()) | `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. |\n| [setText(text)](#setText(String)) | [Text](/apps-script/reference/xml-service/text) | Sets the text value of the `Text` node. |\n\nDetailed documentation\n----------------------\n\n### `append(text)`\n\nAppends the given text to any content that already exists in the node.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|--------------------------------|\n| `text` | `String` | the text to append to the node |\n\n#### Return\n\n\n[Text](/apps-script/reference/xml-service/text) --- the `Text` node, for chaining\n\n*** ** * ** ***\n\n### `detach()`\n\nDetaches the node from its parent [Element](/apps-script/reference/xml-service/element) node. If the node does not have a parent,\nthis method has no effect.\n\n#### Return\n\n\n[Content](/apps-script/reference/xml-service/content) --- the detached node\n\n*** ** * ** ***\n\n### `get``Parent``Element()`\n\nGets the node's parent [Element](/apps-script/reference/xml-service/element) node. If the node does not have a parent, this method\nreturns `null`.\n\n#### Return\n\n\n[Element](/apps-script/reference/xml-service/element) --- the parent `Element` node\n\n*** ** * ** ***\n\n### `get``Text()`\n\nGets the text value of the `Text` node.\n\n#### Return\n\n\n`String` --- the text value of the `Text` node\n\n*** ** * ** ***\n\n### `get``Value()`\n\nGets the text value of all nodes that are direct or indirect children of the node, in the order\nthey appear in the document.\n\n#### Return\n\n\n`String` --- the text value of all nodes that are direct or indirect children of the node\n\n*** ** * ** ***\n\n### `set``Text(text)`\n\nSets the text value of the `Text` node.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|-----------------------|\n| `text` | `String` | the text value to set |\n\n#### Return\n\n\n[Text](/apps-script/reference/xml-service/text) --- the `Text` node, for chaining"]]