Propriété XML DOM nodeName
❮ Objet d'attribut
Exemple
Le fragment de code suivant charge « books.xml » dans xmlDoc, affiche le nom du nœud, la valeur du nœud et le type de nœud de l'attribut de catégorie :
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 x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book');
for (i = 0; i < x.length; i++) {
txt += x.item(i).attributes[0].nodeName +
" = " +
x.item(i).attributes[0].nodeValue
+
" (nodetype: " + x.item(i).attributes[0].nodeType
+ ")" + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
Sortir:
category = cooking (nodetype: 2)
category = children (nodetype: 2)
category = web (nodetype: 2)
category = web (nodetype: 2)
Définition et utilisation
La propriété nodeName renvoie le nom d'un nœud, en fonction de son type.
Syntaxe
attrObject.nodeName
❮ Objet d'attribut