एक्सएमएल डोम आइटम () विधि
NamedNodeMap वस्तु
उदाहरण
निम्नलिखित कोड खंड " 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, i, att, xmlDoc,
txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book');
for (i = 0; i < x.length; i++) {
att = x.item(i).attributes.getNamedItem("category");
txt += att.value + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
उपरोक्त कोड का आउटपुट होगा:
cooking
children
web
web
परिभाषा और उपयोग
आइटम () विधि नोड सूची में निर्दिष्ट सूचकांक पर नोड लौटाती है।
वाक्य - विन्यास
item(index)
Parameter | Description |
---|---|
index | The index |
ट्राई-इट-योरसेल्फ डेमो
NamedNodeMap वस्तु