Class Attribute

属性

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);

メソッド

メソッド戻り値の型概要
getName()String属性のローカル名を取得します。
getNamespace()Namespace|null属性の名前空間を取得します。
getValue()String属性の値を取得します。
setName(name)Attribute属性のローカル名を設定します。
setNamespace(namespace)Attribute属性の Namespace を設定します。
setValue(value)Attribute属性の値を設定します。

詳細なドキュメント

getName()

属性のローカル名を取得します。属性に名前空間接頭辞がある場合は、getNamespace() を使用します。getPrefix(): 接頭辞を取得します。

戻る

String - 属性のローカル名。


getNamespace()

属性の名前空間を取得します。

戻る

Namespace|null - 属性の名前空間。


getValue()

属性の値を取得します。

戻る

String - 属性の値。


setName(name)

属性のローカル名を設定します。属性の Namespace 接頭辞を設定するには、XmlService.getNamespace(prefix, uri) と組み合わせて setNamespace(namespace) を使用します。

パラメータ

名前説明
nameString設定するローカル名。

戻る

Attribute - チェーン用の属性。


setNamespace(namespace)

属性の Namespace を設定します。名前空間には接頭辞が必要です。

パラメータ

名前説明
namespaceNamespace設定する Namespace。

戻る

Attribute - チェーン用の属性。


setValue(value)

属性の値を設定します。

パラメータ

名前説明
valueString設定する値。

戻る

Attribute - チェーン用の属性。