JavaScript 读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].nodeValue;
[解决办法]
[江湖追杀通缉令]:
经本人查证,此LZ从来不结贴。望广大网友周知。查证时间:2007-8-31。
验证方式:搜索,作者,添入作者名。发现所有贴子均未结……