Uma representação de um atributo XML.
// 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);
Métodos
| Método | Tipo de retorno | Breve descrição |
|---|---|---|
get | String | Recebe o nome local do atributo. |
get | Namespace | Recebe o namespace do atributo. |
get | String | Recebe o valor do atributo. |
set | Attribute | Define o nome local do atributo. |
set | Attribute | Define o namespace do atributo. |
set | Attribute | Define o valor do atributo. |
Documentação detalhada
get Name()
Recebe o nome local do atributo. Se o atributo tiver um prefixo de namespace, use get.get para receber o prefixo.
Retornar
String: o nome local do atributo
get Namespace()
get Value()
Recebe o valor do atributo.
Retornar
String: o valor do atributo
set Name(name)
Define o nome local do atributo. Para definir um prefixo de namespace para o atributo, use set em conjunto com Xml.
Parâmetros
| Nome | Tipo | Descrição |
|---|---|---|
name | String | o nome local a ser definido |
Retornar
Attribute: o atributo para encadeamento
set Namespace(namespace)
set Value(value)
Define o valor do atributo.
Parâmetros
| Nome | Tipo | Descrição |
|---|---|---|
value | String | o valor a ser definido |
Retornar
Attribute: o atributo para encadeamento