XML DOM getElementsByTagNameNS()เมธอด
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books_ns.xml " ลงใน xmlDoc และรับองค์ประกอบตามชื่อแท็กและเนมสเปซ:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagNameNS("https://www.w3schools.com/children/",
"title");
document.getElementById("demo").innerHTML =
x[0].nodeName;
}
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
c:title
ความหมายและการใช้งาน
เมธอด getElementsByTagNameNS() ส่งคืน NodeList ขององค์ประกอบทั้งหมดที่มีชื่อและเนมสเปซที่ระบุ
ไวยากรณ์
elementNode.getElementsByTagNameNS(ns,name)
Parameter | Description |
---|---|
ns | A string that specifies the namespace to search for. The value "*" matches all tags |
name | A string that specifies the tagname to search for. The value "*" matches all tags |
❮ วัตถุธาตุ