XML DOM getAttributeNode() ဘက်တွင်

ဒီပညာ

getAttributeNode() getAttributeNode() ဘက်တွင် ဖြင့် လက်ရှိ အအုပ်အချက်မှ အချက်အလက်အချက်အလက် ကို ရယူပါ

အပိုင်းအချက်

elementNode.getAttributeNode(name)
သဘောကြီး ဖော်ပြ
name လိုအပ်ချက်

အကြောင်းကြောင်း

အောက်ရှိ ကြောင်းရပ်များ "books.xml" ကို xmlDoc သို့ တင်ကာ <book> အအုပ်အချက်အလက်များ မှ "category" အချက်အလက် ကို ရယူပါလိမ့်မည်

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, attnode, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for (i = 0; i < x.length; i++) {
        attnode = x.item(i).getAttributeNode("category");
        txt += attnode.name + " = " + attnode.value + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

ကိုယ်တိုင် ကြိုးစားဘူး