Class Attribute
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Özellik
Bir XML özelliğinin temsili.
// Reads the first and last name of each person and adds a new attribute with
// the full name.
let xml = '<roster>' +
'<person first="John" last="Doe"/>' +
'<person first="Mary" last="Smith"/>' +
'</roster>';
const document = XmlService.parse(xml);
const people = document.getRootElement().getChildren('person');
for (let i = 0; i < people.length; i++) {
const person = people[i];
const firstName = person.getAttribute('first').getValue();
const lastName = person.getAttribute('last').getValue();
person.setAttribute('full', `${firstName} ${lastName}`);
}
xml = XmlService.getPrettyFormat().format(document);
Logger.log(xml);
Ayrıntılı dokümanlar
getName()
Özelliğin yerel adını alır. Özelliğin ad alanı ön eki varsa getNamespace()
kullanın.getPrefix()
.
Return
String
: Özelliğin yerel adı
getNamespace()
Özelliğin ad alanını alır.
Return
Namespace
: Özelliğin ad alanı
getValue()
Özelliğin değerini alır.
Return
String
: Özelliğin değeri
setNamespace(namespace)
Özelliğin ad alanını belirler. Ad alanında bir ön ek olmalıdır.
Parametreler
Ad | Tür | Açıklama |
namespace | Namespace | ayarlanacak ad alanı |
Return
Attribute
: zincirleme için özellik
setValue(value)
Özelliğin değerini ayarlar.
Parametreler
Ad | Tür | Açıklama |
value | String | ayarlanacak değer |
Return
Attribute
: zincirleme için özellik
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-26 UTC.
[null,null,["Son güncelleme tarihi: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eAttribute\u003c/code\u003e object represents an XML attribute and provides methods for manipulating its name, namespace, and value.\u003c/p\u003e\n"],["\u003cp\u003eYou can get an attribute's local name using \u003ccode\u003egetName()\u003c/code\u003e, its namespace using \u003ccode\u003egetNamespace()\u003c/code\u003e, and its value using \u003ccode\u003egetValue()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003esetName()\u003c/code\u003e, \u003ccode\u003esetNamespace()\u003c/code\u003e, and \u003ccode\u003esetValue()\u003c/code\u003e allow modifying an attribute's local name, namespace, and value respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates how to iterate through XML elements, access their attributes, and add new attributes.\u003c/p\u003e\n"]]],["The `Attribute` class represents an XML attribute, allowing for manipulation of its properties. Key actions include retrieving the attribute's name, namespace, and value using `getName()`, `getNamespace()`, and `getValue()`. Modifications are possible via `setName(name)`, `setNamespace(namespace)`, and `setValue(value)`. An example demonstrates reading \"first\" and \"last\" names from an XML, creating a new \"full\" attribute by concatenating these names. The methods allow retrieving and setting of attribute data.\n"],null,["# Class Attribute\n\nAttribute\n\nA representation of an XML attribute.\n\n```javascript\n// Reads the first and last name of each person and adds a new attribute with\n// the full name.\nlet xml = '\u003croster\u003e' +\n '\u003cperson first=\"John\" last=\"Doe\"/\u003e' +\n '\u003cperson first=\"Mary\" last=\"Smith\"/\u003e' +\n '\u003c/roster\u003e';\nconst document = XmlService.parse(xml);\nconst people = document.getRootElement().getChildren('person');\nfor (let i = 0; i \u003c people.length; i++) {\n const person = people[i];\n const firstName = person.getAttribute('first').getValue();\n const lastName = person.getAttribute('last').getValue();\n person.setAttribute('full', `${firstName} ${lastName}`);\n}\nxml = XmlService.getPrettyFormat().format(document);\nLogger.log(xml);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------|-----------------------------------------------------------|---------------------------------------|\n| [getName()](#getName()) | `String` | Gets the local name of the attribute. |\n| [getNamespace()](#getNamespace()) | [Namespace](/apps-script/reference/xml-service/namespace) | Gets the namespace for the attribute. |\n| [getValue()](#getValue()) | `String` | Gets the value of the attribute. |\n| [setName(name)](#setName(String)) | [Attribute](#) | Sets the local name of the attribute. |\n| [setNamespace(namespace)](#setNamespace(Namespace)) | [Attribute](#) | Sets the namespace for the attribute. |\n| [setValue(value)](#setValue(String)) | [Attribute](#) | Sets the value of the attribute. |\n\nDetailed documentation\n----------------------\n\n### `get``Name()`\n\nGets the local name of the attribute. If the attribute has a namespace prefix, use [getNamespace()](#getNamespace()).[getPrefix()](/apps-script/reference/xml-service/namespace#getPrefix()) to get the prefix.\n\n#### Return\n\n\n`String` --- the local name of the attribute\n\n*** ** * ** ***\n\n### `get``Namespace()`\n\nGets the namespace for the attribute.\n\n#### Return\n\n\n[Namespace](/apps-script/reference/xml-service/namespace) --- the namespace for the attribute\n\n*** ** * ** ***\n\n### `get``Value()`\n\nGets the value of the attribute.\n\n#### Return\n\n\n`String` --- the value of the attribute\n\n*** ** * ** ***\n\n### `set``Name(name)`\n\nSets the local name of the attribute. To set a namespace prefix for the attribute, use [setNamespace(namespace)](#setNamespace(Namespace)) in conjunction with [XmlService.getNamespace(prefix, uri)](/apps-script/reference/xml-service/xml-service#getNamespace(String,String)).\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|-----------------------|\n| `name` | `String` | the local name to set |\n\n#### Return\n\n\n[Attribute](#) --- the attribute, for chaining\n\n*** ** * ** ***\n\n### `set``Namespace(namespace)`\n\nSets the namespace for the attribute. The namespace must have a prefix.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|-----------------------------------------------------------|----------------------|\n| `namespace` | [Namespace](/apps-script/reference/xml-service/namespace) | the namespace to set |\n\n#### Return\n\n\n[Attribute](#) --- the attribute, for chaining\n\n*** ** * ** ***\n\n### `set``Value(value)`\n\nSets the value of the attribute.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|------------------|\n| `value` | `String` | the value to set |\n\n#### Return\n\n\n[Attribute](#) --- the attribute, for chaining"]]