Metodo hasAttributeNS() del DOM XML
Definizione e uso
Se l'elemento nodo corrente possiede un attributo di nome spazio e nome specificato: hasAttributeNS()
Il metodo restituisce true, altrimenti restituisce false.
Sintassi
hasAttributeNS(ns,name)
Parametri | Descrizione |
---|---|
ns | Obbligatorio. Specifica lo spazio dei nomi dell'attributo da cercare. |
name | Obbligatorio. Specifica il nome dell'attributo da cercare. |
Esempio
Il codice seguente carica "books_ns.xml" nella xmlDoc e verifica se l'elemento <title> primario ha qualsiasi attributo di nome spazio e nome specificato:
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.hasAttributeNS(ns,"lang"); {}