// Reads the first and last name of each person and adds a new attribute with// the full name.letxml='<roster>'+'<person first="John" last="Doe"/>'+'<person first="Mary" last="Smith"/>'+'</roster>';constdocument=XmlService.parse(xml);constpeople=document.getRootElement().getChildren('person');for(leti=0;i < people.length;i++){constperson=people[i];constfirstName=person.getAttribute('first').getValue();constlastName=person.getAttribute('last').getValue();person.setAttribute('full',`${firstName}${lastName}`);}xml=XmlService.getPrettyFormat().format(document);Logger.log(xml);
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-12-22 (世界標準時間)。"],[[["`Attribute` object represents an XML attribute and provides methods for manipulating its name, namespace, and value."],["You can get an attribute's local name using `getName()`, its namespace using `getNamespace()`, and its value using `getValue()`."],["`setName()`, `setNamespace()`, and `setValue()` allow modifying an attribute's local name, namespace, and value respectively."],["The provided code example demonstrates how to iterate through XML elements, access their attributes, and add new attributes."]]],["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"]]