I am having a some problems in getting a node value from a XML file
My XML looks like this:
<item>
<item1><Description>test</Description></item1>
<item2><Description>test2</Description></item2>
<item3><Description>test3</Description></item3>
</item>
And I am trying to get 'test2' from Item2 > Description.
I am able to get the xml file display in a alert messagebox but can't seem to get the value i am looking for.
I am trying to do this in JavaScript and so far I have come up with the following:
function get_item()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
xmlDoc = xmlhttp.responseText;
var item = xmlDoc.getElementsByTagName("Description")[0];
item = item.childNodes.length ? item.childNodes[0].nodeValue : "" ;
alert(item)
} else
{
alert('Panel not communicating.Reason: '+xmlhttp.status);
}
}
xmlhttp.open("POST","http://192.168.0.5/xml_file.xml",false);
xmlhttp.send();
}
If I remove:
var item = xmlDoc.getElementsByTagName("Description")[0];
item = item.childNodes.length ? item.childNodes[0].nodeValue : "" ;
and change the alert to:
alert(xmlDoc)
it alerts my XML file, so i know it's reading my xml file but can't get the value.
Am I doing something wrong or is there a better way to get this value?
(I don't want to use jQuery for this)