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)

속성의 로컬 이름을 설정합니다. 속성의 네임스페이스 접두사를 설정하려면 XmlService.getNamespace(prefix, uri)와 함께 setNamespace(namespace)를 사용합니다.

매개변수

이름유형설명
nameString설정할 로컬 이름

리턴

Attribute: 체이닝을 위한 속성


setNamespace(namespace)

속성의 네임스페이스를 설정합니다. 네임스페이스에는 프리픽스가 있어야 합니다.

매개변수

이름유형설명
namespaceNamespace설정할 네임스페이스

리턴

Attribute: 체이닝을 위한 속성


setValue(value)

속성의 값을 설정합니다.

매개변수

이름유형설명
valueString설정할 값

리턴

Attribute: 체이닝을 위한 속성