xml 读的时候有错误,大家帮我看看啊!
readxml.html 页代码
<!DOCTYPE HTML PUBLIc "1//W3C//DTD XHTML 1.0 Strict//EN "
"http://www.w3.org/TR/xhtml1/DTD/xhtmll1-strict.dtd ">
<html xmlns= "http;//www.w3.org/1999/xhtml ">
<head>
<title> xmlHttprequest </title>
<meta name= "GENERATOR " content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "ProgId " content= "VisualStudio.HTML ">
<meta name= "Originator " content= "Microsoft Visual Studio .NET 7.1 ">
<script language= "javascript ">
var xmlHttp;
var requestType= " ";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
else(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function startRequest(requestedList)
{
// alert( "运行到这里! ");
requestType=requestedList;
createXMLHttpRequest();
alert( "运行到这里! ");
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open( "GET ", "city.xml ",true);
xmlHttp.send(null);
}
function handleStateChange()
{
//alert( "运行到这里! ");
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(requestType== "north ")
{
listNorthStates();
}
else if(requestType== "All ")
{
listAllStates();
}
}
}
}
function listNorthStates()
{
//alert( "运行到这里! ");
var xmlDoc=xmlHttp.responseXML;
var northNode=xmlDoc.getElementsByTagName( "north ");
// var out= "Northen States ";
var northStates=norhtNode.getElementsByTagName( "state ");
outputList( "Northen States ",northStates);
}
function listAllStates()
{
var xmlDoc=xmlHttp.responseXML;
var allStates=xmlDoc.getElementsByTagName( "state ");
outputList( "All States ",allStates);
}
function outputList(title,states)
{
var out=title;
var currentStates=null;
for(var i=0;i <states.length;i++)
{
currentStates=states[i];
out=out + "\n- " +currentStates.childNodes[0].nodeValue;
}
alert(out);
}
</script>
</head>
<body>
<FONT face= "宋体 "> </FONT>
<form>
<input type=button value= "All States here " onclick= "startRequest( 'All '); "/>
<br/>
<br/>
<input type=button value= "North States here " onclick= "startRequest( 'states '); ">
</form>
</body>
</html>
city.xml 页代码
<?xml version= "1.0 " encoding= "utf-8 " ?>
<states>
<north>
<state> beijing </state>
<state> shijiazhuang </state>
<state> langfang </state>
</north>
<south>
<state> guangzhou </state>
<state> shenzhen </state>
<state> xiamen </state>
</south>
<east>
<state> shanghai </state>
<state> wenzhou </state>
<state> nanjing </state>
</east>
<west>
<state> xizang </state>
<state> guizhou </state>
<state> yunnan </state>
</west>
</states>
[解决办法]
代码太长,就没有你对问题的描述?
[解决办法]
var XmlRoot = DOM.documentElement;
XmlRoot.childNodes[0];
[解决办法]
XmlRoot.childNodes[0].nodeValue;
[解决办法]
程序有问题
if(requestType== "north ")
{
listNorthStates();
}
else if(requestType== "All ")
{
listAllStates();
}
这个感觉条件好怪。
还有,请用DOM直接读取,不要用XMLHTTP,无需多此1举创建多个对象
var xmlDoc = new ActiveXObject( "Microsoft.XMLDOM ");
xmlDoc.load(ServerUrl + "city.xml?dd= " + Date());