XML DOM အကွင်းလုပ်သည်

အကွင်းလုပ် (Traverse) သည် အကွင်းလုပ်သည် အစိတ်အပိုင်းများ တွင် အကြောင်းကြည့်ခြင်း သို့မဟုတ် ပြောင်းလဲခြင်းကို ဖော်ပြသည်。

အကျိုးအတွက်

ဤအကျိုးအတွက် အရင်းအမြစ် XML အချက်အလက်များ ကို အသုံးပြုသည် books.xml

ပုဂ္ဂိုလ် loadXMLString()အခြား JavaScript တွင် နေရာတန့်ချိန်တွင် အသုံးပြုသည်。

အကွင်းလုပ်သည် အကွင်းလုပ်သည်
အကြောင်းအရာ <book> အစိတ်အပိုင်းများ အား အကြောင်းကြည့်သည်。

အကွင်းလုပ်သည်

သင်သည် အချိန်ကျသော အခါတွင် အရင်းအမြစ် XML အချက်အလက်များ ကို အကြောင်းကြည့်သင့်သည်။ ဥပမာ၊ အခါတွင် အရင်းအမြစ် အရာများ၏ အသုံးချမှုကို တွေ့ရှိသင့်သည်。

ဤအပြုအမူကို "အကွင်းလုပ်သည်" ဟု ခေါ်ဝင်းသည်。

ဤအကျိုးအတွက် အကြောင်းအရာ <book> ရဲ့ တိုက်ရိုက်သား အစိတ်အပိုင်းများ ကို ချီလိုက်သည်။

<html>
<head>
<script type="text/javascript" src="loadxmlstring.js"></script>
</head>
<body>
<script type="text/javascript">
text="<book>";
text=text+"<title>Harry Potter</title>";
text=text+"<author>J K. Rowling</author>";
text=text+"<year>2005</year>";
text=text+"</book>";
xmlDoc=loadXMLString(text);
// documentElement always represents the root node
x=xmlDoc.documentElement.childNodes;
for (i=0;i<x.length;i++)
{
document.write(x[i].nodeName);
document.write(": ");
document.write(x[i].childNodes[0].nodeValue);
document.write("<br />");
}
</script>
</body>
</html>

ပြန်ပေး

title: Harry Potter
author: J K. Rowling
year: 2005

အကျိုးသတင်း အရာ

  • loadXMLString() XML အချက်အလက် ကို xmlDoc အား ဆောက်လုပ်
  • အခြေခံ အား ဂိုဏ်း အပိုင်းစား ကို ရယူ
  • ခွင့်ပြု ရှိသော အပိုင်းစား အား အမည် နှင့် အချက်အလက် ကို ပြန်ပေး

TIY