XML DOM cloneNode() Yöntemi
❮ Düğüm Nesnesi
Örnek
Aşağıdaki kod parçası " books.xml " dosyasını yükler, ilk <book> düğümünü klonlar ve ardından onu düğüm listesinin sonuna ekler:
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;
}
Yukarıdaki kodun çıktısı şöyle olacaktır:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Everyday Italian
Tanım ve Kullanım
klonNode() yöntemi, bir düğümün bir kopyasını oluşturur ve yeni klonlanan düğümü döndürür.
Tarayıcı Desteği
klonNode() yöntemi, tüm büyük tarayıcılarda desteklenir.
Sözdizimi
nodeObject.cloneNode(deep)
parametreler
Parameter | Type | Description |
---|---|---|
deep | Boolean | true clones the node, its attributes, and its descendants.
false clones the node and its attributes. |
Geri dönüş değeri
Type | Description |
---|---|
Node object | The cloned node |
Teknik detaylar
DOM Sürümü | Çekirdek Düzey 1 Düğüm Nesnesi |
---|
❮ Düğüm Nesnesi