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;
{}

직접 시험해 보세요