XML DOM attribute nodeValue
Ορισμός και χρήση
nodeValue
Η ρύθμιση ή η επιστροφή της τιμής του στοιχείου, ανάλογα με τον τύπο του.
σύνταξη
attrObject.nodeValue
παράδειγμα
Η παρακάτω κώδικας θα φορτώσει το "books.xml" στο xmlDoc και θα εμφανίσει το όνομα του στοιχείου category, την τιμή του και τον τύπο του:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = λειτουργία() { αν (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); λειτουργία myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('book'); για (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; }