XML DOM childNodes özelliği
Tanım ve Kullanım
childNodes
Belirli bir düğümün alt düğümlerini döndüren özellik.
İpucu:length özelliğini kullanarak alt düğüm sayısını belirleyebilir ve ardından tüm alt düğümleri dolaşarak istediğiniz bilgileri çıkarabilirsiniz.
Sözdizimi
nodeObject.childNodes
Teknik ayrıntılar
Dönüş değeri: | Düğüm kümesi ifade eden NodeList nesnesi. |
---|---|
DOM Sürümü: | Core Level 1 |
Örnek
Örnek 1
Aşağıdaki kod "books.xml" dosyasını xmlDoc içine yükler ve XML belgesinin alt düğümlerini gösterir:
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, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.childNodes; for (i = 0; i < x.length; i++) { txt += "Nodename: " + x[i].nodeName + " (nodetype: " + x[i].nodeType + ")"; } document.getElementById("demo").innerHTML = txt; }
Örnek 2
所有元素的所有子节点显示在 XML 文档中:
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, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.documentElement; y = x.childNodes; for(i = 0; i < y.length; i++) { txt += "Nodename: " + y[i].nodeName + " (nodetype: " + y[i].nodeType + ")<br>"; for(z = 0; z < y[i].childNodes.length; z++) { txt += "Nodename: " + y[i].childNodes[z].nodeName + " (nodetype: " + y[i].childNodes[z].nodeType + ")<br>"; } } document.getElementById("demo").innerHTML = "Nodename: " + xmlDoc.nodeName + " (nodetype: " + xmlDoc.nodeType + ")<br>" "Nodename: " + x.nodeName +"}} " (nodetype: " + x.nodeType + ")<br>" + txt; }
Tarayıcı Desteği
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Desteklenir | Desteklenir | Desteklenir | Desteklenir | Desteklenir |
Tüm popüler tarayıcılar destekler childNodes
Özellikler.