XML DOM removeAttributeNode() 메서드

정의와 사용법

removeAttributeNode() 메서드는 지정된 속성 노드를 제거합니다.

DTD에서 속성의 기본 값이 정의되어 있으면 즉시 기본 값이 있는 새 속성이 생성됩니다.

이 함수는 제거된 속성 노드를 반환합니다.

문법

elementNode.removeAttributeNode(node)
파라미터 설명
node 필수. 제거할 노드.

예제

아래 코드는 "books.xml"를 xmlDoc에 로드하고 모든 <book> 요소에서 "category" 속성 노드를 제거합니다:

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 x, i, attnode, old_att, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for (i = 0; i < x.length; i++) {
        while (x[i].attributes.length > 0) {
            attnode = x[i].attributes[0];
            old_att = x[i].removeAttributeNode(attnode);
            txt += "Removed: " + old_att.nodeName +"}}"
            : " + old_att.nodeValue + "<br>";
        }
    }
document.getElementById("demo").innerHTML = txt;
}

직접 테스트해 보세요