Metodo XML DOM splitText()
❮ Oggetto CDATA
Esempio
Il seguente frammento di codice carica " books_cdata.xml " in xmlDoc e divide il testo nel primo nodo CDATA:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_cdata.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("html")[0].childNodes[0];
var y = x.splitText(8);
document.getElementById("demo").innerHTML
=
x.nodeValue + "<br>" + y.nodeValue;
}
Produzione:
Stunn
ing!
Definizione e utilizzo
Il metodo splitText() divide il nodo di testo in due nodi all'offset specificato.
Questa funzione restituisce il nodo contenente il testo dopo l'offset.
Il testo prima dell'offset rimane nel nodo di testo originale.
Sintassi
replaceData(offset)
Parameter | Description |
---|---|
offset | Required. Specifies where to split the text node. Offset value starts at zero |
❮ Oggetto CDATA