Método getAttributeNS() del XML DOM
Definición y uso
getAttributeNS()
El método obtiene el valor del atributo a través del URI del espacio de nombres y el nombre.
Sintaxis
elementNode.getAttributeNS(ns,name)
Parámetros | Descripción |
---|---|
ns | Obligatorio. Especifica el URI del espacio de nombres del atributo del cual se debe obtener el valor. |
name | Obligatorio. Especifica el atributo del cual se debe obtener el valor. |
Ejemplo
El siguiente código carga "books_ns.xml" en xmlDoc y obtiene el valor del 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/"; document.getElementById("demo").innerHTML = x.getAttributeNS(ns, "lang"); }