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);
メソッド
| メソッド | 戻り値の型 | 概要 |
|---|---|---|
get | String | 属性のローカル名を取得します。 |
get | Namespace|null | 属性の名前空間を取得します。 |
get | String | 属性の値を取得します。 |
set | Attribute | 属性のローカル名を設定します。 |
set | Attribute | 属性の名前空間を設定します。 |
set | Attribute | 属性の値を設定します。 |
詳細なドキュメント
getName()
属性のローカル名を取得します。属性に名前空間の接頭辞がある場合は、getNamespace() を使用します。getPrefix() を使用して接頭辞を取得します。
戻る
String \- 属性のローカル名。
getNamespace()
getValue()
属性の値を取得します。
戻る
String \- 属性の値。
setName(name)
属性のローカル名を設定します。属性の名前空間の接頭辞を設定するには、XmlService.getNamespace(prefix, uri) と組み合わせて setNamespace(namespace) を使用します。
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
name | String | 設定するローカル名。 |
戻る
Attribute \- チェーン用の属性。