XML DOM appendData() 메서드
정의와 사용법
appendData()
주석 노드의 끝에 데이터를 추가하는 메서드.
문법
commentNode.appedData(string)
파라미터 | 설명 |
---|---|
string | 必需. 주석 노드에 추가할 문자열. |
예제
아래 코드는 "books_comment.xml" 파일을 xmlDoc에 로드하고, 첫 번째 주석 요소에 텍스트를 추가합니다:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_comment.xml", true); xhttp.send(); function myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book")[0].childNodes; for (i = 0; i < x.length; i++) { // 만약 댓글 노드만 처리합니다. Process only comment nodes if (x[i].nodeType == 8) { x[i].appendData("특별 제안"); txt += x[i].data + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
위의 예제에서는 루프와 if 테스트 문장을 사용하여注释 노드만 처리하는 것을 보장했습니다.注释 노드의 노드 타입은 8입니다.