XML DOM removeChild() metodu

tanım ve kullanım

removeChild() methodu silmek için alt node

Başarı durumunda bu fonksiyon silinen node'yu döner, başarısız durumda döner NULL

gramer

elementNode.removeChild(node)
parametre tanım
node Gerekli. Silinecek alt node belirtir.

örnek

örnek 1

Aşağıdaki kod "books.xml" dosyasını xmlDoc'ye yükler ve ilk <book> elementindeki alt node'ları siler:

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 xmlDoc = xml.responseXML;
    var y = xmlDoc.getElementsByTagName("book")[0];
    var x = xmlDoc.documentElement.removeChild(y);
    document.getElementById("demo").innerHTML =
    "Silinen düğüm: " + x.nodeName;
}

Kişisel olarak deneyin

örnek 2

从节点列表中删除最后一个子节点:

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 xmlDoc = xml.responseXML;
    var len = xmlDoc.getElementsByTagName('book').length;
    var y = xmlDoc.getElementsByTagName("book")[len-1];
    var x = xmlDoc.documentElement.removeChild(y);
    document.getElementById("demo").innerHTML =
    "Silinen düğüm: " + x.nodeName;
}

Kişisel olarak deneyin