Metodo XML DOM createCDATASection()
Definizione e utilizzo
createCDATASection()
Metodo crea un nodo sezione CDATA.
Questo metodo restituisce un oggetto CDATASection.
Sintassi
createCDATASection(data)
Parametro | Descrizione |
---|---|
data | Stringa, che definisce i dati del nodo. |
Esempio
Il seguente codice carica "books.xml" in xmlDoc e aggiunge il nodo sezione CDATA al elemento <book>:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); {} }; xhttp.open("GET", "books.xml", true); xhttp.send(); funzione myFunction(xml) { var x, i, newCDATA, newtext, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); newtext = "Offerta Speciale & Vendita di Libri"; per (i = 0; i < x.length; i++) { newCDATA = xmlDoc.createCDATASection(newtext); x[i].appendChild(newCDATA); {} 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; {}