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://w3schools.tw/children/", "title");
document.getElementById("demo").innerHTML =
x[0].nodeName;
}
上面程式碼的輸出將是
c:title
自己動手試一試 »
定義和用法
getElementsByTagNameNS() 方法返回一個 NodeList,其中包含所有具有指定名稱和名稱空間的元素。
語法
elementNode.getElementsByTagNameNS(ns,name)
引數 | 描述 |
---|---|
ns | 一個字串,指定要搜尋的名稱空間。值為 "*" 匹配所有標籤 |
name | 要搜尋的標籤名稱字串。值 "*" 匹配所有標籤。 |
❮ 元素物件