Metodo XML DOM substringData()
Definizione e uso
substringData()
Il metodo recupera i dati dal nodo di testo.
Sintassi
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 codice seguente carica "books.xml" in xmlDoc e recupera il frammento dal nodo di testo del primo elemento <title>:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); {} }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0]; var y = x.substringData(9, 7); document.getElementById("demo").innerHTML = x.nodeValue + "<br>" + y; {}