Class Attribute

屬性

XML 屬性的表示法。

// Reads the first and last name of each person and adds a new attribute with the full name.
var xml = '<roster>'
    + '<person first="John" last="Doe"/>'
    + '<person first="Mary" last="Smith"/>'
    + '</roster>';
var document = XmlService.parse(xml);
var people = document.getRootElement().getChildren('person');
for (var i = 0; i < people.length; i++) {
  var person = people[i];
  var firstName = person.getAttribute('first').getValue();
  var lastName = person.getAttribute('last').getValue();
  person.setAttribute('full', firstName + ' ' + lastName);
}
xml = XmlService.getPrettyFormat().format(document);
Logger.log(xml);

方法

方法傳回類型簡短說明
getName()String取得屬性的當地名稱。
getNamespace()Namespace取得屬性的命名空間。
getValue()String取得屬性的值。
setName(name)Attribute設定屬性的當地名稱。
setNamespace(namespace)Attribute設定屬性的命名空間。
setValue(value)Attribute設定屬性的值。

內容詳盡的說明文件

getName()

取得屬性的當地名稱。如果屬性含有命名空間前置字元,請使用 getNamespace()getPrefix() 取得前置字串。

回攻員

String:屬性的本機名稱


getNamespace()

取得屬性的命名空間。

回攻員

Namespace:屬性的命名空間


getValue()

取得屬性的值。

回攻員

String:屬性值


setName(name)

設定屬性的當地名稱。如要為屬性設定命名空間前置字串,請將 setNamespace(namespace)XmlService.getNamespace(prefix, uri) 搭配使用。

參數

名稱類型說明
nameString要設定的本機名稱

回攻員

Attribute — 屬性 (用於鏈結)


setNamespace(namespace)

設定屬性的命名空間。命名空間必須包含前置字串。

參數

名稱類型說明
namespaceNamespace要設定的命名空間

回攻員

Attribute — 屬性 (用於鏈結)


setValue(value)

設定屬性的值。

參數

名稱類型說明
valueString要設定的值

回攻員

Attribute — 屬性 (用於鏈結)