XML DOM localName అట్రిబ్యూట్
నిర్వచనం మరియు వినియోగం
localName
అట్రిబ్యూట్ ఎండ్ ఎలమెంట్ యొక్క స్థానిక పేరును తిరిగి తెలుపుతుంది (ఎలమెంట్ పేరు).
ఎండ్ ఎలమెంట్ లేదా అట్రిబ్యూట్ కాదు ఉన్నప్పుడు ఈ అట్రిబ్యూట్ నుండి NULL తిరిగి తెలుపుతుంది.
సంకేతం
elementNode.localName
ప్రతిమాత్రము
ఉదాహరణ 1
క్రింది కోడు "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 xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName("book")[0]; document.getElementById("demo").innerHTML = x.localName; }
ఉదాహరణ 2
క్రింది కోడు "books.xml" ను xmlDoc లోకి లోడ్ చేస్తుంది మరియు చివరి కుమార నోడ్ నుండి స్థానిక పేరును పొందుతుంది:
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 get_lastchild(n) { var x = n.lastChild; while (x.nodeType != 1) { x = x.previousSibling; } return x; } function myFunction(xml) { var xmlDoc = xml.responseXML; var x = xmlDoc.documentElement; var lastNode = get_lastchild(x); document.getElementById("demo").innerHTML = lastNode.localName; }