خصائص XML DOM nodeName

التعريف والاستخدام

nodeName الخصائص تعود بناءً على النوع.

النحو

attrObject.nodeName

مثال

الكود التالي سيفتح ملف "books.xml" ويظهر اسم العنصر، قيمة العنصر ونوع العنصر لخصائص category:

مفردات xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = وظيفة() {
   إذا (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
وظيفة myFunction(xml) {
    مفردات 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;
}

جرب بنفسك