XML DOM appendData() Methode
Definition und Verwendung
appendData()
Diese Methode fügt Daten am Ende eines Kommentar-Knotens hinzu.
Syntax
commentNode.appendData(Zeichenkette)
Parameter | Beschreibung |
---|---|
Zeichenkette | Erforderlich. Die Zeichenkette, die zum Kommentar-Knoten hinzugefügt werden soll. |
Beispiel
Nachstehender Code lädt "books_comment.xml" in xmlDoc und fügt den Text dem ersten Kommentar-Element hinzu:
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++) { // Nur Comment-Nodes verarbeiten if (x[i].nodeType == 8) { x[i].appendData("Special Offer"); txt += x[i].data + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
In the above example, we used loops and if test statements to ensure that we only handle comment nodes. The node type of comment nodes is 8.