Propiedad de contenido de texto DOM XML
❮ Objeto de nodo
Ejemplo
El siguiente fragmento de código carga " books.xml " en xmlDoc y devuelve el contenido textual de los elementos <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();
function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x =
xmlDoc.getElementsByTagName('book');
for(i = 0; i <
x.length; i++) {
txt += x.item(i).textContent
+ "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
La salida del código anterior será:
Everyday Italian Giada De Laurentiis 2005 30.00
Harry Potter J K. Rowling 2005 29.99
XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn
Vaidyanathan Nagarajan 2003 49.99
Learning XML Erik T. Ray 2003 39.95
Definición y uso
La propiedad textContent establece o devuelve el contenido textual de un nodo y sus descendientes.
En la configuración, los nodos secundarios se eliminan y se reemplazan por un solo nodo de texto que contiene la cadena en la que se establece esta propiedad.
Sintaxis
nodeObject.textContent
Demostraciones para que lo pruebe usted mismo
❮ Objeto de nodo