Metodo getAttributeNodeNS() del DOM XML
Definizione e uso
getAttributeNS()
Il metodo ottiene il nodo dell'attributo utilizzando l'URI dello spazio dei nomi e il nome.
Sintassi
elementNode.getAttributeNodeNS(ns,name)
Parametri | Descrizione |
---|---|
ns | Obbligatorio. Specifica l'URI dello spazio dei nomi. |
name | Obbligatorio. Specifica il nome dell'attributo. |
Esempio
Il codice seguente carica "books_ns.xml" nel xmlDoc e recupera il nodo di attributo "lang" dal primo elemento <title>:
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; }