【发布时间】:2013-12-06 05:50:54
【问题描述】:
我正在尝试从 notes.xml 解析 xml,它在 firebug 中显示错误为
TypeError: xml.getElementsByTagName is not a function
我的代码部分是,
notes.xml
<fr>
<franchise city="Scottsdale" state=" AZ" />
<franchise city="Arcadia" state=" CA" />
</fr>
javascript
<script>
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","notes.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("franchise");
alert(x.getElementsByTagName("state")[0].childNodes[0].nodeValue);
</script>
【问题讨论】:
标签: javascript html xml xml-parsing