Metodo getElementsByTagNameNS() del DOM XML
Definizione e uso
getElementsByTagNameNS()
Il metodo restituisce un NodeList, che contiene tutti gli elementi con il nome e lo spazio dei nomi specificati.
Sintassi
elementNode.getElementsByTagNameNS(ns,name)
Parametro | Descrizione |
---|---|
ns | Stringa, che specifica lo spazio dei nomi da cercare. Il valore "*" corrisponde a tutte le etichette. |
name | Stringa, che specifica il nome dell'etichetta da cercare. Il valore "*" corrisponde a tutte le etichette. |
Esempio
Il seguente codice carica "books_ns.xml" nel xmlDoc e ottiene gli elementi tramite il nome dell'etichetta e lo spazio dei nomi:
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.getElementsByTagNameNS("https://www.codew3c.com/meishi/", "title"); document.getElementById("demo").innerHTML = x[0].nodeName; {}