Load xml file using javascript
Nothing gets printed on the web page when I try to open an HTML file
having javascript. The script inside the html code loads the xml file and
tries to print some element data. I have pasted the code below. Sadly no
data of file gets printed. I have used browsers IE8 and Chrome. Please let
me know what is the issue.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLDOM");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script>
xmlDoc=loadXMLDoc("file:///E:/Parser/book.xml");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue
+ " <br>");
document.write(xmlDoc.getElementsByTagName("authors")[0].childNodes[0].nodeValue
+ "<br>");
</script>
</body>
</html>
No comments:
Post a Comment