XML DOM getAttributeNode() روش
تعریف و استفاده
getAttributeNode()
روشها برای دریافت نقطهی ویژگی از عنصر فعلی.
قوانین
elementNode.getAttributeNode(name)
پارامترها | توضیح |
---|---|
name | ضروری. تعیین نقطهی ویژگی مورد نظر. |
مثال
کد زیر "books.xml" را به xmlDoc بارگذاری کرده و از ویژگی "category" تمام عناصر <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, attnode, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('book'); برای (i = 0; i < x.length; i++) { attnode = x.item(i).getAttributeNode("category"); txt += attnode.name + " = " + attnode.value + "<br>"; } document.getElementById("demo").innerHTML = txt; }