การแสดงแอตทริบิวต์ 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 | ตั้งค่าแอตทริบิวต์ |
เอกสารโดยละเอียด
get Name()
รับชื่อแอตทริบิวต์ในภาษาท้องถิ่น หากแอตทริบิวต์มีคำนำหน้าเนมสเปซ ให้ใช้ getget เพื่อรับคำนำหน้า
รีเทิร์น
String — ชื่อแอตทริบิวต์ในภาษาท้องถิ่น
get Namespace()
get Value()
รับค่าของแอตทริบิวต์
รีเทิร์น
String — ค่าของแอตทริบิวต์
set Name(name)
ตั้งค่าชื่อแอตทริบิวต์ในเครื่อง หากต้องการตั้งค่าคำนำหน้าเนมสเปซสำหรับแอตทริบิวต์ ให้ใช้ set ร่วมกับ Xml
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
name | String | ชื่อในพื้นที่ที่จะตั้ง |
รีเทิร์น
Attribute — แอตทริบิวต์สำหรับการเชื่อมโยง
set Namespace(namespace)
set Value(value)
ตั้งค่าแอตทริบิวต์
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
value | String | ค่าที่จะตั้ง |
รีเทิร์น
Attribute — แอตทริบิวต์สำหรับการเชื่อมโยง