Método substringData() do XML DOM
Definição e uso
substringData()
O método obtém dados do nó de texto.
Sintaxe
substringData(start,length)
Parâmetros | Descrição |
---|---|
start | Obrigatório. Especifica a partir de onde começar a extrair caracteres. O valor de início é zero. |
length | Obrigatório. Especifica o número de caracteres a serem extraídos. |
Exemplo
A seguir, o código carregará "books.xml" para xmlDoc e obterá o trecho do nó de texto do primeiro 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; {}