Método insertData() do XML DOM
Definição e uso
insertData()
O método insere dados no nó de texto.
Sintaxe
insertData(start,string)
Parâmetros | Descrição |
---|---|
start | Obrigatório. Especifica a partir de onde começar a inserir caracteres. O valor de início é zero. |
string | Obrigatório. Especifica a string a ser inserida. |
Exemplo
A seguir, o código carregará "books.xml" para xmlDoc e inserirá a string no 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]; x.insertData(0,"Cooking: "); document.getElementById("demo").innerHTML = x.data; }