XML DOM lookupNameSpaceURI() 方法

定义和用法

lookupNameSpaceURI() 方法返回与给定的前缀相关联的命名空间 URI。

语法

nodeObject.lookupNamespaceURI(prefix)

参数

参数 描述
prefix 必需。字符串。规定要查找的前缀。

技术细节

DOM 版本: Core Level 3 Node Object
返回值: 与指定的前缀相关联的命名空间 URI。

实例

下面的代码将 "books_ns.xml" 加载到 xmlDoc 中,并查找给定的 "c" 前缀的命名空间 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.lookupNamespaceURI("c");
}

Probieren Sie es selbst aus

Browserunterstützung

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Unterstützt Unterstützt Unterstützt Unterstützt Unterstützt

Alle gängigen Browser unterstützen dies. lookupNamespaceURI("c"); Methode.

Anmerkung: Internet Explorer 9 und frühere Versionen unterstützen diese Methode nicht.