XML DOM getAttributeNodeNS() روش

تعریف و استفاده

getAttributeNS() این روش از طریق URI نام‌گذاری شده و نام به گره ویژگی دسترسی دارد.

قانون‌گذاری

elementNode.getAttributeNodeNS(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/";
    var y = x.getAttributeNodeNS(ns,"lang");
    document.getElementById("demo").innerHTML =
    y.nodeName + " = " + y.nodeValue;
}

آزمایش کنید