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 | Отсоединяет узел от его родительского узла Element . |
get Parent Element() | Element | Получает родительский узел Element узла. |
get Text() | String | Получает текстовое значение узла Text . |
get Value() | String | Получает текстовое значение всех узлов, которые являются прямыми или косвенными дочерними элементами узла, в том порядке, в котором они появляются в документе. |
set Text(text) | Text | Устанавливает текстовое значение узла Text . |
Подробная документация
append(text)
Добавляет заданный текст к любому содержимому, которое уже существует в узле.
Параметры
Имя | Тип | Описание |
---|
text | String | текст для добавления к узлу |
Возвращаться
Text
— узел Text
для объединения в цепочку.
detach()
Отсоединяет узел от его родительского узла Element
. Если у узла нет родителя, этот метод не имеет никакого эффекта.
Возвращаться
Content
— отдельный узел
get Parent Element()
Получает родительский узел Element
узла. Если у узла нет родителя, этот метод возвращает null
.
Возвращаться
Element
— родительский узел Element
.
get Text()
Получает текстовое значение узла Text
.
Возвращаться
String
— текстовое значение узла Text
get Value()
Получает текстовое значение всех узлов, которые являются прямыми или косвенными дочерними элементами узла, в том порядке, в котором они появляются в документе.
Возвращаться
String
— текстовое значение всех узлов, которые являются прямыми или косвенными дочерними элементами узла.
set Text(text)
Устанавливает текстовое значение узла Text
.
Параметры
Имя | Тип | Описание |
---|
text | String | текстовое значение для установки |
Возвращаться
Text
— узел Text
для объединения в цепочку.
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 UTC."],[[["\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"]]