XML DOM attribute एट्रिब्यूट
वर्णन और उपयोग
attribute
एट्रिब्यूट NamedNodeMap (एट्रिब्यूट सूची) वापस करता है जिसमें चयनित नोड के एट्रिब्यूट्स शामिल हैं。
यदि चयनित नोड एलीमेंट नहीं है, तो इस एट्रिब्यूट ने NULL वापस किया है。
सूचना:यह एट्रिब्यूट केवल एलीमेंट नोड के लिए ही उपयोगी है。
व्याकरण
elementNode.attributes
उदाहरण
इस कोड के माध्यम से "books.xml" को xmlDoc में लोड किया जाता है और "books.xml" में पहले <title> एलीमेंट में एट्रिब्यूट की संख्या प्राप्त की जाती है:
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 xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName("book")[0].attributes; document.getElementById("demo").innerHTML = x.length; }
उदाहरण
2 इस कोड के माध्यम से "books.xml" को xmlDoc में लोड किया जाता है और पहले <book> एलीमेंट में "category" एट्रिब्यूट के मालूम की जाती है: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; }