Método hasAttribute() del DOM XML

Definición y uso

Si el nodo actual tiene una propiedad con el nombre especificado, hasAttribute() El método devuelve true, de lo contrario devuelve false.

Sintaxis

hasAttribute(name)
Parámetros Descripción
name Obligatorio. Especifica el atributo que se debe buscar.

Ejemplo

El siguiente código cargará "books.xml" en xmlDoc y verificará si el primer elemento <book> tiene alguna propiedad "category":

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 &&this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("book")[0];
    document.getElementById("demo").innerHTML =
    x.hasAttribute("category");
}

Prueba personalmente