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
، برای زنجیر
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 Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\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"]]