XML DOM ma metodę AttributeNS()
❮ Obiekt elementu
Przykład
Poniższy fragment kodu ładuje " books_ns.xml " do xmlDoc i sprawdza, czy pierwszy element <title> ma jakiekolwiek atrybuty określonej przestrzeni nazw i nazwy:
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");
}
Wyjście:
true
Definicja i użycie
Metoda hasAttributeNS() zwraca TRUE, jeśli węzeł bieżącego elementu ma atrybut określony przez przestrzeń nazw i nazwę, a FALSE w przeciwnym razie.
Składnia
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 |
❮ Obiekt elementu