XML DOM getAttributeNS() పద్ధతి

నిర్వచనం మరియు వినియోగం

getAttributeNS() నామకపదము URI మరియు పేరు ద్వారా అట్రిబ్యూట్ విలువను పొందే మార్గం.

విధానం

elementNode.getAttributeNS(ns,name)
పరామితులు వివరణ
ns అవసరం. అట్రిబ్యూట్ విలువను పొందడానికి నిర్దేశిస్తుంది నామకపదము URI.
name అవసరం. అట్రిబ్యూట్ విలువను పొందడానికి నిర్దేశిస్తుంది అట్రిబ్యూట్.

ప్రతిరూపం

ఈ కోడు "books_ns.xml" ని xmlDoc లోకి లోడ్ చేస్తుంది మరియు మొదటి <title> ఎలమెంట్ నుండి "lang" అట్రిబ్యూట్ విలువను పొందుతుంది:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0];
    var ns = "https://www.codew3c.com/meishi/";
    document.getElementById("demo").innerHTML =
    x.getAttributeNS(ns, "lang");
}

亲自试一试