Método getAttributeNodeNS() del DOM XML
Definición y uso
getAttributeNS()
El método obtiene el nodo de atributo mediante el URI del espacio de nombres y el nombre.
Sintaxis
elementNode.getAttributeNodeNS(ns,name)
Parámetros | Descripción |
---|---|
ns | Obligatorio. Especifica el URI del espacio de nombres. |
name | Obligatorio. Especifica el nombre del atributo. |
Ejemplo
El siguiente código carga "books_ns.xml" en xmlDoc y obtiene el nodo de atributo "lang" del primer 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; {}