XML DOM setAttributeNode() စက်

ဒီအချက်အလက်

setAttributeNode() အကြောင်းကြောင်းပြော

XML DOM setAttributeNode() စက်

အချက်အလက်

အပိုင်းအုပ်

elementNode.setAttributeNode(att_node)
ပါ သုံးသပ်
att_node လိုအပ်သည့်အတွက်။ အသုံးပြုရာ အချက်အလက် အပိုင်းအခြာ

အကြောင်း

အောက်ပါ ကြောင်းအော် "books.xml" ကို xmlDoc ထဲသို့ သို့မဟုတ် အားလုံး <book> အက်ဥ်တ် "edition" အချက်အလက် ပြင်ဆင်ပါ

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, y, z, i, newatt, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for (i = 0; i < x.length; i++) {
        newatt = xmlDoc.createAttribute("edition");
        newatt.value = "first";
        x[i].setAttributeNode(newatt);
    }
    // ပြောက်သတ္တုပိုင်း သုတ်ပုံး အချက်အလက် ထုတ်ပြန်ကြေညာပါ
    for (i = 0; i < x.length; i++) {
        txt += "Edition: " + x[i].getAttribute("edition") + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

ကျွန်တော် ကျင်ချင်တာ