XML DOM cdata length Proprietà
❮ Oggetto CDATA
Esempio
Il seguente frammento di codice carica " books_cdata.xml " in xmlDoc e ottiene i dati e la lunghezza del nodo di testo dal primo elemento <title>:
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];
document.getElementById("demo").innerHTML =
x.data + "
- Length: " + x.length;
}
L'output del codice sopra sarà:
Stunning! - Length: 16
Ricorda che la lunghezza sopra è dell'intera sezione CDATA (<b>Stupefacente!</b>), non solo del testo.
Definizione e utilizzo
La proprietà length restituisce il numero di caratteri nel nodo selezionato
Sintassi
CDATANode.length
❮ Oggetto CDATA