XML DOM cloneNode() 메서드
❮ 노드 객체
예시
다음 코드 조각은 " books.xml "을 로드하고 첫 번째 <book> 노드를 복제한 다음 노드 목록 끝에 추가합니다.
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, y, cloneNode, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book')[0];
cloneNode
= x.cloneNode(true);
xmlDoc.documentElement.appendChild(cloneNode);
//
Output all titles
y = xmlDoc.getElementsByTagName("title");
for (i = 0; i < y.length; i++) {
txt += y[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
위 코드의 출력은 다음과 같습니다.
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
정의 및 사용
cloneNode() 메서드는 노드의 복사본을 만들고 새 복제 노드를 반환합니다.
브라우저 지원
cloneNode() 메서드는 모든 주요 브라우저에서 지원됩니다.
통사론
nodeObject.cloneNode(deep)
매개변수
Parameter | Type | Description |
---|---|---|
deep | Boolean | true clones the node, its attributes, and its descendants.
false clones the node and its attributes. |
반환 값
Type | Description |
---|---|
Node object | The cloned node |
기술적 세부 사항
DOM 버전 | 코어 레벨 1 노드 개체 |
---|
❮ 노드 객체