I'm trying to parse xml from an notes.xml, it show an error in firebug as
TypeError: xml.getElementsByTagName is not a function
My code part is,
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>
Your alert statement is wrong.
x
has no methodgetElementsByTagName
.You can get the first city using:
The second one is:
And states: