Método substringData() del XML DOM
Definición y uso
substringData()
El método obtiene datos de un nodo de texto.
Sintaxis
substringData(start,length)
Parámetros | Descripción |
---|---|
start | Obligatorio. Especifica desde dónde comenzar a extraer caracteres. El valor de inicio es cero. |
length | Obligatorio. Especifica el número de caracteres a extraer. |
Ejemplo
El siguiente código cargará "books.xml" en xmlDoc y obtendrá el fragmento del primer nodo de texto del 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; }