Metodo XML DOM getElementsByTagNameNS()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " book_ns.xml " in xmlDoc e ottiene un elemento in base al nome del tag e allo 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.w3schools.com/children/",
"title");
document.getElementById("demo").innerHTML =
x[0].nodeName;
}
L'output del codice sopra sarà:
c:title
Definizione e utilizzo
Il metodo getElementsByTagNameNS() restituisce un NodeList di tutti gli elementi con un nome e uno spazio dei nomi specificati.
Sintassi
elementNode.getElementsByTagNameNS(ns,name)
Parameter | Description |
---|---|
ns | A string that specifies the namespace to search for. The value "*" matches all tags |
name | A string that specifies the tagname to search for. The value "*" matches all tags |
❮ Oggetto Elemento