خاصية attribute XML DOM

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

خاصية الخاصية تعود NamedNodeMap (قائمة الخاصيات) تحتوي على الخاصيات للعنصر المحدد.

إذا لم يكن العنصر المحدد هو عنصر، فإن هذه الخاصية تعود NULL.

إشارة:هذه الخاصية تنطبق فقط على العناصر.

اللغة

elementNode.attributes

مثال

أيضاً: الكود التالي سيفتح ملف "books.xml" ويحمل إلى xmlDoc ويحصل على عدد الخاصيات للعنصر الـ <title> الأول في ملف "books.xml":

مغيرات xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = وظيفة() {
   إذا (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
وظيفة myFunction(xml) {
    مغيرات xmlDoc = xml.responseXML;
    مغيرات x = xmlDoc.getElementsByTagName("book")[0].attributes;
    document.getElementById("demo").innerHTML =
    x.length;
}

جرب بنفسك

مثال

2 أيضاً: الكود التالي سيفتح ملف "books.xml" ويحمل إلى xmlDoc ويحصل على قيمة الخاصية "category" للعنصر الـ <book> الأول:
مغيرات 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, att, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    لذا (للبدء; i < x.length; i++) {
        att = x.item(i).attributes.getNamedItem("category");
        txt += att.value + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

جرب بنفسك