我有一个 xml 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<food>
<cuisine type="Chinese">
<restaurant name = "Panda Express">
<location id= "0"></location>
<phone id = "1"></phone>
<city id="2"></phone>
</restaurant>
<restaurant name = "Mr. Chau's">
</restaurant>
</cuisine>
<cuisine type="Indian">
<restaurant name = "Shan">
</restaurant>
</cuisine>
</food>
我正在尝试计算美食节点的数量,这是我拥有的代码,我知道它大部分是正确的,但是当我尝试打印节点列表的长度时,它说它是 0
//starts talking to the xml document
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","data.xml", false);
xmlhttp.send();
xmlData = xmlhttp.responseXML;
//fills the first comboBox
var sel = document.getElementById('CuisineList');
cuisineList = xmlData.getElementsByTagName('cuisine');
document.getElementById("test").innerHTML = cuisineList.length;