XML DOM getAttributeNodeNS() Method
Definition and Usage
getAttributeNS()
The method retrieves an attribute node by namespace URI and name.
Syntax
elementNode.getAttributeNodeNS(ns,name)
Parameters | Description |
---|---|
ns | Required. Specifies the namespace URI. |
name | Required. Specifies the attribute name. |
Example
The following code loads "books_ns.xml" into xmlDoc and retrieves the "lang" attribute node from the first <title> element:
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("title")[0]; var ns = "https://www.codew3c.com/meishi/"; var y = x.getAttributeNodeNS(ns,"lang"); document.getElementById("demo").innerHTML = y.nodeName + " = " + y.nodeValue; }