Phương pháp getAttributeNodeNS() của XML DOM
Định nghĩa và cách sử dụng
getAttributeNS()
Phương pháp lấy thuộc tính node thông qua URI không gian tên và tên.
Ngữ pháp
elementNode.getAttributeNodeNS(ns,name)
Tham số | Mô tả |
---|---|
ns | Bắt buộc. Quy định URI không gian tên. |
name | Bắt buộc. Quy định tên thuộc tính. |
Mô hình
Dưới đây là mã nguồn sẽ "books_ns.xml" tải vào xmlDoc và từ phần tử đầu tiên <title> lấy thuộc tính node "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; {}