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 - 用于链接的属性