Metodo XML DOM createComment()
Definizione e uso
createComment()
Metodo che crea un nodo di commento.
Questo metodo restituisce un oggetto Comment.
Sintassi
createComment(data)
Parametro | Descrizione |
---|---|
data | Stringa, che definisce i dati del nodo. |
Esempio
Il codice seguente carica "books.xml" in xmlDoc e aggiunge il nodo di commento al elemento <book>:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { se (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); funzione myFunction(xml) { var x, i, newComment, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); per (i = 0; i < x.length; i++) { newComment = xmlDoc.createComment("Revised April 2008"); x[i].appendChild(newComment); } per (i = 0; i < x.length; i++) { txt += x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + " - " + x[i].lastChild.nodeValue + "<br>"; } document.getElementById("demo").innerHTML = txt; }