Class Cdata
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
CData (em inglês)
Uma representação de um nó CDATASection
XML.
// 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);
Documentação detalhada
append(text)
Anexa o texto fornecido a qualquer conteúdo que já exista no nó.
Parâmetros
Nome | Tipo | Descrição |
text | String | o texto a ser anexado ao nó |
Retornar
Text
: o nó Text
, para encadeamento
detach()
Desconecta o nó do nó Element
pai. Se o nó não tiver um pai,
esse método não terá efeito.
Retornar
Content
: o nó removido
getParentElement()
Recebe o nó Element
pai do nó. Se o nó não tiver um pai, esse método
vai retornar null
.
Retornar
Element
: o nó Element
pai
getText()
Recebe o valor de texto do nó Text
.
Retornar
String
: o valor de texto do nó Text
getValue()
Recebe o valor de texto de todos os nós que são filhos diretos ou indiretos do nó, na ordem
em que aparecem no documento.
Retornar
String
: o valor de texto de todos os nós que são filhos diretos ou indiretos do nó
setText(text)
Define o valor de texto do nó Text
.
Parâmetros
Nome | Tipo | Descrição |
text | String | o valor de texto a ser definido |
Retornar
Text
: o nó Text
, para encadeamento
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-26 UTC.
[null,null,["Última atualização 2025-07-26 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"]]