Método hasChildNodes() do XML DOM
Definição e uso
Se o nó de elemento atual tiver nós filhos, então hasChildNodes()
O método retorna true, caso contrário, retorna false.
Sintaxe
elementNode.hasChildNodes()
Exemplo
O código a seguir carrega "books.xml" para xmlDoc e verifica se o primeiro elemento <book> possui qualquer nó filho:
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.hasChildNodes(); }