不能';t使用javascript在网页中显示xml数据

不能';t使用javascript在网页中显示xml数据,javascript,html,xml,Javascript,Html,Xml,我试图通过访问XMLDOM并使用javascript将数据显示为表格式来显示包含一些信息的xml文件。尝试通过创建xml http请求来编写下面的函数,但仍然无法获得任何用于显示数据的输出 <html> <head> </head> <body> <p>Please enter id(100 or 105)</p> <p>Input id (106) to view the entire details</

我试图通过访问XMLDOM并使用javascript将数据显示为表格式来显示包含一些信息的xml文件。尝试通过创建xml http请求来编写下面的函数,但仍然无法获得任何用于显示数据的输出

<html>
<head>
</head>
<body>
<p>Please enter id(100 or 105)</p>
<p>Input id (106) to view the entire details</p>
<script type="text/javascript">
function display()
{
var y=document.getElementById('hifi').value
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","user.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 
var x=xmlDoc.getElementsByTagName("Persondetails");
document.write("<table><tr><th>id</th><th>name</th></tr>");
for(i=0;i<x.length;i++)
{
var z=x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
if(z==y)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("name")            [0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
else if(y==106)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("name")    [0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
else if(y<100 || y>106)
{
window.alert("Input is invalid");
}
}
document.write("</table>");
}
</script>
<form name="myform">
        Enter id :<input id="hifi" type="number" min="100" max="106"/>
                   <input type="button" value="Submit" onclick="display()"/>
 </form>


</body>
</html>



 <?xml version="1.0" encoding="UTF-8"?>
 <student>
 <Persondetails>
 <id>100</id>
 <name>tamizh</name>
 </Persondetails>
 <Persondetails>
 <id>101</id>
 <name>amal</name>
 </Persondetails>
 <Persondetails>
 <id>102</id>
 <name>ice cream</name>
 </Persondetails>
 <Persondetails>
 <id>103</id>
 <name>haa</name>
 </Persondetails>
 <Persondetails>
 <id>104</id>
 <name>rocky</name>
 </Persondetails>
 <Persondetails>
 <id>105</id>
 <name>ra</name>
 </Persondetails>
 <Persondetails>
 <id>106</id>
 <name>r</name>
 </Persondetails>
 </student>

请输入id(100或105)

输入id(106)以查看整个详细信息

函数显示() { var y=document.getElementById('hifi')。值 if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代码 xmlhttp=新的XMLHttpRequest(); } 其他的 {//IE6、IE5的代码 xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”); } open(“GET”,“user.xml”,false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var x=xmlDoc.getElementsByTagName(“个人信息”); 文件。填写(“idname”); 对于(i=0;i