Metodo substringData() del DOM XML

Definizione e uso

substringData() Il metodo recupera una stringa dal nodo CDATA.

Sintassi

CDATANode.substringData(start,length)
Parametro Descrizione
start Obbligatorio. Specifica da dove iniziare a estrarre i caratteri. Il valore di partenza è zero.
length Obbligatorio. Specifica il numero di caratteri da estrarre.

Esempio

Il seguente codice carica "books_cdata.xml" nel xmlDoc e ottiene la stringa "Stun" dal primo elemento 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.substringData(3, 4);
    document.getElementById("demo").innerHTML =
    x.nodeValue + "<br>" + y;
{}

Prova personalmente