XML DOM createElement() နည်းလမ်း

အသုံးချက် နှင့် လက်ဆင့်ကမ်း

createElement() နည်းလမ်း

ထိုအက္ခရာ သည် Element အားကစ္စာကို ပြန်လည်ပေးသည်

အက္ခရာ

createElement(သတင်း)
ပါ အပ်စ်
သတင်း ကုဒ်အမည်

အကြောင်းအရာ

အောက်ပါ ကြောက်ချက် သည် "books.xml" ကို xmlDoc အတွက် တင်သွင်းပြီး အသုံးပြုသော <book> အီးယူအချက်အလက် ခုံးဝင်အချက်အလက် အသုံးပြုသည်

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, xLen, yLen, newEle, newText, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book");
    xLen = x.length;
    // အစုအဖွဲ့ အီးယူအချက်အလက် နှင့် စကားလုံး အချက်အလက်
    for (i = 0; i < xLen; i++) {
        newEle = xmlDoc.createElement("edition");
        newText = xmlDoc.createTextNode("first");
        newEle.appendChild(newText);
        x[i].appendChild(newEle);
    }
    // အားလုံးပါဝင်သော title နှင့် edition ထုတ်ပြန်ချက်
    y = xmlDoc.getElementsByTagName("title");
    yLen = y.length
    z = xmlDoc.getElementsByTagName("edition");
    for (i = 0; i < yLen; i++) {
        txt += y[i].childNodes[0].nodeValue +
        " - Edition: " +
       z[i].childNodes[0].nodeValue + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

ကိုယ်တိုင် စမ်းသပ်ပါ