myData.xml
<?xml version='1.0'?>
<root>
<data>
<text>
<author>P C Tejaswi</author>
<book>Karvaalo</book>
<award>State Academy</award>
</text>
<text>
<author>Kuvempu</author>
<book>Ramayana Darshanam</book>
<award>Gnanapeeta</award>
</text>
</data>
</root>
myData.html
<!DOCTYPE html>
<html>
<body>
<h1>DOM usage </h1>
<p id="para">
</p>
<script>
function loadFile(name){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",name,false);
xhttp.send();
return xhttp.responseXML;
}
xmldoc = loadFile("myData.xml");
x = xmldoc.getElementsByTagName("book")[0].childNodes[0];
x.deleteData(0,8)
x.insertData(0,"Parisara Kathegalu");
document.write(x.nodeValue);
</script>
</body>
</html>
Output of above example:
<book>Karvaalo</book> is replaced to
<book>Parisara Kathegalu</book>
Comments
No comments have been made yet.
Please login to leave a comment. Login now