Retrieving Information From XML using Javascript


#1

My xml code:

<?xml version="1.0" encoding="UTF-8"?>
<EMPLOYEES>
<EMPLOYEE>
<ID>100</ID>
<NAME>RAM</NAME>
<DESIGN>MANAGER</DEGIGN>
</EMPLOYEE>
<EMPLOYEE>
<ID>101</ID>
<NAME>RAj</NAME>
<DESIGN>ASST MANAGER</DEGIGN>
</EMPLOYEE>
<EMPLOYEE>
<ID>102</ID>
<NAME>SAM</NAME>
<DESIGN>TRAINEE</DEGIGN>
</EMPLOYEE>
<EMPLOYEE>
<ID>103</ID>
<NAME>sae</NAME>
<DESIGN>MD</DEGIGN>
</EMPLOYEE>
</EMPLOYEES>

My HTML code:

<!DOCTYPE html>
<html>
<head>
<title>Retrieve</title>
<style>
table,th,td{
border:1px solid black;
border-collapse:collapse;
}
th,td{
padding:5px;
}
</style>
</head>
<body>
<h1>Retrieving Information From XML</h1>
SID:<input type="text" id="id"></input>
<button onclick="test()">Submit</button>
<script>
function test()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","web.xml",false);
xhttp.send();
xmlDoc=xmlhttp.responseXML;
var tmp1;
tmp1=parseInt(document.getElemetById('id').value);
document.writeln(tmp1+"<table>");
document.write("<tr><th>ID</th><th>NAME</th><th>DESIGNATION</th></tr>");
var x =xmlDoc.getElementByTagName("EMPLOYEE");
for(i=0;i<x.length;i++)
{
var tmp=parseInt(x[i].getElementByTagName("ID")[0].childNodes[0].nodeValue);
if(tmp==tmp1)
{
document.write("<tr><td>");
document.wrte(x[i].getElementByTagName("ID")[0].childNodes[0].nodeValue);
docunemt.write("</td><td>");
document.wrte(x[i].getElementByTagName("NAME")[0].childNodes[0].nodeValue);
docunemt.write("</td><td>");
document.wrte(x[i].getElementByTagName("DESIGN")[0].childNodes[0].nodeValue);
docunemt.write("</td><td>");
documet.write("</td></tr>");
}
}
document.write("</table>");

}
</script>
</body>
</html>

Here I am not able to get the information. In IE I get Access Denied Problem could anyone help me.


#2

i put your code here:

https://repl.it/@stetim94/PoisedUnitedComputing

and i get a very different error:

ReferenceError: xhttp is not defined

the problem is that access denied errors are very difficult to debug, given its very difficult to replicate that kind of problem.