XML DOM createElementNS() မီးရူး
အသုံးပြုခြင်း နှင့် အပြုအရင်
createElementNS()
ဒါမှာ အမှတ်ပုံစံ အရာများ ကို အမှတ်ပုံစံ အရာများ ဖြင့် ဖွဲ့စည်းပါ
ဒါမှာ Element အရာများ ကို ပြန်လည်ပေးသော တုံ့ဖြတ် တွေ့ရသည်
ပုံစံ
createElementNS(ns,name)
ပါ | ဖော်ပြ |
---|---|
ns | ကွင်းစား သည် အရာအသုံးပြုပါ |
name | ကွင်းစား သည် အရာအသုံးပြုပါ |
အကြောင်းအရာ
အောက်ပါ ကြောင်းရာ သည် "books.xml" ကို xmlDoc ထဲသို့ သို့မဟုတ် ရုပ်ပိုင်းအသုံးပြုပါ
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, newel, newtext, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); // အမှတ်ပုံစံ နှင့် စကားလုံး သို့မဟုတ် အသုံးပြုပါ for (i = 0; i < x.length; i++) { newel = xmlDoc.createElementNS("p", "edition"); newtext = xmlDoc.createTextNode("First"); newel.appendChild(newtext); x[i].appendChild(newel); } // အားလုံး title နှင့် edition တို့ ပြန့်ပြောကြားပါ y = xmlDoc.getElementsByTagName("title"); z = xmlDoc.getElementsByTagNameNS("p","edition"); for (i = 0; i < y.length; i++) { txt += y[i].childNodes[0].nodeValue + " - " + z[i].childNodes[0].nodeValue + " edition." + " Namespace: " + z[i].namespaceURI + "<br>"; } document.getElementById("demo").innerHTML = txt; }