Attribute

A representation of an XML attribute.

```javascript
// 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);
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/xml-service/attribute#getName()` | `String` | Gets the local name of the attribute. |
| `https://developers.google.com/apps-script/reference/xml-service/attribute#getNamespace()` | `https://developers.google.com/apps-script/reference/xml-service/namespace|null` | Gets the namespace for the attribute. |
| `https://developers.google.com/apps-script/reference/xml-service/attribute#getValue()` | `String` | Gets the value of the attribute. |
| `https://developers.google.com/apps-script/reference/xml-service/attribute#setName(String)` | `https://developers.google.com/apps-script/reference/xml-service/attribute#` | Sets the local name of the attribute. |
| `https://developers.google.com/apps-script/reference/xml-service/attribute#setNamespace(Namespace)` | `https://developers.google.com/apps-script/reference/xml-service/attribute#` | Sets the namespace for the attribute. |
| `https://developers.google.com/apps-script/reference/xml-service/attribute#setValue(String)` | `https://developers.google.com/apps-script/reference/xml-service/attribute#` | Sets the value of the attribute. |

## Detailed documentation

### `getName()`

Gets the local name of the attribute. If the attribute has a namespace prefix, use `https://developers.google.com/apps-script/reference/xml-service/attribute#getNamespace()`.`https://developers.google.com/apps-script/reference/xml-service/namespace#getPrefix()` to get the prefix.

#### Return


`String` --- The local name of the attribute.

*** ** * ** ***

### `getNamespace()`

Gets the namespace for the attribute.

#### Return


`https://developers.google.com/apps-script/reference/xml-service/namespace|null` --- The namespace for the attribute.

*** ** * ** ***

### `getValue()`

Gets the value of the attribute.

#### Return


`String` --- The value of the attribute.

*** ** * ** ***

### `setName(name)`

Sets the local name of the attribute. To set a namespace prefix for the attribute, use `https://developers.google.com/apps-script/reference/xml-service/attribute#setNamespace(Namespace)` in conjunction with `https://developers.google.com/apps-script/reference/xml-service/xml-service#getNamespace(String,String)`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | The local name to set. |

#### Return


`https://developers.google.com/apps-script/reference/xml-service/attribute#` --- The attribute, for chaining.

*** ** * ** ***

### `setNamespace(namespace)`

Sets the namespace for the attribute. The namespace must have a prefix.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `namespace` | `https://developers.google.com/apps-script/reference/xml-service/namespace` | The namespace to set. |

#### Return


`https://developers.google.com/apps-script/reference/xml-service/attribute#` --- The attribute, for chaining.

*** ** * ** ***

### `setValue(value)`

Sets the value of the attribute.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `value` | `String` | The value to set. |

#### Return


`https://developers.google.com/apps-script/reference/xml-service/attribute#` --- The attribute, for chaining.