Stay organized with collections Save and categorize content based on your preferences.
AttributeA representation of an XML attribute.
// 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);Detailed documentation
getName()
Gets the local name of the attribute. If the attribute has a namespace prefix, use getNamespace()
.getPrefix()
to get the prefix.
String
— the local name of the attribute
getNamespace()
Gets the namespace for the attribute.
ReturnNamespace
— the namespace for the attribute
getValue()
Gets the value of the attribute.
ReturnString
— the value of the attribute
setNamespace(namespace)
Sets the namespace for the attribute. The namespace must have a prefix.
Parameters Name Type Descriptionnamespace
Namespace
the namespace to set Return
Attribute
— the attribute, for chaining
setValue(value)
Sets the value of the attribute.
Parameters Name Type Descriptionvalue
String
the value to set Return
Attribute
— the attribute, for chaining
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["`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"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4