Propriedade de comprimento XML DOM
❮ Objeto NamedNodeMap
Exemplo
O fragmento de código a seguir carrega " books.xml " em xmlDoc e obtém o número de atributos no primeiro elemento <book>:
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");
document.getElementById("demo").innerHTML =
"Number of
attributes in the first book element: " +
x.item(0).attributes.length;
}
A saída do código acima será:
Number of attributes in the first book element:
1
Definição e uso
A propriedade length retorna o número de nós em um NamedNodeMap.
Sintaxe
nodemapObject.length
Demonstrações de teste você mesmo
❮ Objeto NamedNodeMap