XML DOM خصائص nodeType

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

nodeType الخصائص تعود إلى نوع العنصر.

النص

attrObject.nodeType

مثال

السطر التالي سيزيد "books.xml" إلى xmlDoc ويظهر اسم الخصائص والقيمة والنوع للعنصر:

تعريفية 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;
}

جرب بنفسك