I'm nearing my wits' end here on what should be a simple problem. I'm trying to use javascript to parse and return values from a very simple XML document to a very simple HTML document. My problem is that my script refuses to do this. The XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<man>
<name>Nicholas</name>
</man>
<man>
<name>Peter</name>
</man>
</root>
This is strictly for my own education, hence the purposeless tags.
The JavaScript:
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","dname",false);
xmlhttp.send();
return xmlhttp.responseXML;
}
xmlDoc = loadXMLDoc("https://dl.dropboxusercontent.com/u/22818342/Testing/javascript_test4.xml");
x = xmldoc.getElementsByTagName("name");
var content = function()
{
document.write(x[0].childNodes[0].nodeValue);
};
</script>
Note that I'm using my Dropbox public folder to enable the HTTP-fetching part of the code. All these files are located in the same directory.
The (relevant) HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="https://dl.dropboxusercontent.com/u/22818342/Testing/javascript_test3.css" rel="stylesheet" type="text/css" />
<body>
<button type="button" onclick="content()">Click Me</button>
<body>
Also note that when I click the button, ostensibly firing the content() function, nothing happens--it's not a matter of everything being overwritten.
Other relevant information: --I'm testing this in Google Chrome --I lifted much of this code (again, learning purposes only) from the W3Schools XML-parsing demo and from another StackOverflow post from a user with a similar problem to mine. In both cases the code ran fine; it's only when I attempt to run it that things gum up. --I'm fairly new to Javascript and the XML DOM, so it's entirely possible that I made an elementary error somewhere.
I'd appreciate any help the community can provide.
xmlhttp.open("GET", dname, false);