The XML file and Javascript file to load the XML.
myData.xml
<?xml version='1.0'?>
<root>
<data>
<text>
<author>P C Tejaswi</author>
<books>Karvaalo</books>
<award>State Academy</award>
</text>
<text>
<author>Kuvempu</author>
<books>Ramayana Darshanam</books>
<award>Gnanapeeta</award>
</text>
</data>
</root>
myData.html
<!DOCTYPE html>
<html>
<body>
<h3>DOM usage </h3>
<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");
document.write(xmldoc.documentElement.nodeName + " ");
document.write(xmldoc.getElementsByTagName("author")[0].childNodes[0].nodeValue + " ");
document.write(xmldoc.getElementsByTagName("book")[0].childNodes[0].nodeValue + " ");
document.write(xmldoc.getElementsByTagName("award")[0].childNodes[0].nodeValue + " ");
</script>
</body>
</html>
//output
DOM usage
root P C Tejaswi Karvaalo State Academy
Comments
No comments have been made yet.
Please login to leave a comment. Login now