How to load an XML document?
I have done this before, but for some reason I can't get my Javascript
code to load an xml document I made.
function setId()
{
var istream = loadXMLDoc("hangulquiz.xml");
alert(JSON.stringify(istream));
$placeHolder = istream.getElementsByTagName("baseVowels").childNodes;
alert(JSON.stringify($placeHolder));
}
I looked up how to load an XML document and found this function:
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
What am I doing wrong? I'm familiar with most of the DOM functions, like
nextChild, parentNode, etc. But either I'm using it wrong or the load
function isn't working how it should.
EDIT: No console errors, but my alerts reveal these:
{"location":null}
undefined
EDIT2: Also, it would be nice if I could find a way to traverse XML that
works on all browsers, as this method doesn't work on Chrome.
here's the fiddle for the xml: http://jsfiddle.net/p9GQL/
No comments:
Post a Comment