Metodo XML DOM hasAttributeNS()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books_ns.xml " in xmlDoc e controlla se il primo elemento <title> ha attributi dello spazio dei nomi e del nome specificati:
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.w3schools.com/children/";
document.getElementById("demo").innerHTML =
x.hasAttributeNS(ns,"lang");
}
Produzione:
true
Definizione e utilizzo
Il metodo hasAttributeNS() restituisce TRUE se il nodo dell'elemento corrente ha l'attributo specificato da namespace e name, e FALSE in caso contrario.
Sintassi
hasAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to find |
name | Required. Specifies the name of the attribute to find |
❮ Oggetto Elemento