XML DOM အရှည် ပိုင်ဆိုင်မှု
❮ မှတ်ချက် Object
ဥပမာ
အောက်ဖော်ပြပါ ကုဒ်အပိုင်းအစသည် " books_comment.xml " ကို xmlDo c သို့ တင်မည်ဖြစ်ပြီး ၊ ပထမ <title> ဒြပ်စင်မှ စာသား node ဒေတာနှင့် အရှည်ကို ရယူသည်-
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET",
"books_comment.xml", true);
xhttp.send();
function myFunction(xml) {
var x, i,
xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i = 0; i < x.length; i++) {
// Process only
comment nodes
if (x[i].nodeType
== 8) {
txt += x[i].length + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
အထက်ဖော်ပြပါ ကုဒ်၏ အထွက်သည်-
44
အထက်ဖော်ပြပါ ဥပမာတွင် ကျွန်ုပ်တို့သည် မှတ်ချက် node များကိုသာ လုပ်ဆောင်ကြောင်း သေချာစေရန် loop တစ်ခုနှင့် if-test ကို အသုံးပြုပါသည်။ မှတ်ချက် Node တစ်ခုတွင် node အမျိုးအစား 8 ရှိသည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
အရှည်ပိုင်ဆိုင်မှုသည် မှတ်ချက် Node တစ်ခုရှိ စာသား၏အရှည် (စာလုံးများဖြင့်) ပြန်ပေးသည်။
အထားအသို
commentNode.length
❮ မှတ်ချက် Object