XML DOM lookupPrefix()メソッド
❮要素オブジェクト
例
次のコードフラグメントは、「books_ns.xml」をxmlDocにロードし、指定された名前空間URIのプレフィックスを検索します。
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.getElementsByTagName("book")[0];
document.getElementById("demo").innerHTML =
x.lookupPrefix("https://www.w3schools.com/children/");
}
出力:
c
定義と使用法
lookupPrefix()メソッドは、現在のノードで指定された名前空間URIに一致するプレフィックスを返します。
構文
elementNode.lookupPrefix(URI)
Parameter | Description |
---|---|
URI | Required. The namespace URI for the prefix to find |
❮要素オブジェクト