I'm trying to parse a simple XML file but I'm having trouble trying to obtain a value I need. The current error message I'm getting says node is not an object or is null. I'm testing on both I.E. 6, 7, FF 2,3
Here's the XML file:
<bookstore>
<appSettings>
<add key="myKey" value="myTargetValue"/>
</appSettings>
</bookstore>
Here's the script I'm trying to use:
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
if (window.XMLHttpRequest)
{
xhttp = new window.XMLHttpRequest()
}
else
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP")
}
xhttp.open("GET","test.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;
alert(xmlDoc.xml)
var xpath = "/bookstore/appSettings/add[@key='myKey']";
var node = xmlDoc.selectSingleNode(xpath);
alert(node.getAttribute("value"));
</script>
<body>
</body>
</html>
Please advise. Thank you.