Proprietà lunghezza DOM XML
❮ Oggetto NamedNodeMap
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e ottiene il numero di attributi nel primo 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;
}
L'output del codice sopra sarà:
Number of attributes in the first book element:
1
Definizione e utilizzo
La proprietà length restituisce il numero di nodi in una NamedNodeMap.
Sintassi
nodemapObject.length
Dimostrazioni fai-da-te
❮ Oggetto NamedNodeMap