I have a sample xml file as follows:
<?xml version="1.0" encoding="utf-8" ?>
<Countries>
<Country>
<CountryName>United States</CountryName>
<Population>300 million</Population>
<Government>Federal Republic</Government>
</Country>
<Country>
<CountryName>Japan</CountryName>
<Population>72 million</Population>
<Government>Constitutional Monarchy</Government>
</Country>
</Countries>
I then have a javascript code as follows:
<script type="text/javascript">
var xmlobj=new CreateNewObject();
function LoadCustomers()
{
if (xmlobj)
{
xmlobj.open("GET", "http://" + location.host + "/Website1/test.xml", false);
xmlobj.send(null);
if (xmlobj.status==200)
{
var xmlDoc=xmlobj.responseXML;
var nodes=xmlDoc.selectNodes("//Countries/Country/Name/text()");
var ctrl=document.getElementById("ddlCustomers");
for (var i=0; i<nodes.length; i++)
{
var name=nodes[i].nodeValue;
var htmlCode=document.createElement('option');
ctrl.options.add(htmlCode);
htmlCode.text=name;
htmlCode.value=name;
}
} else
{
alert('There was a problem retrieving data');
}
}
}
function DispCustomers()
{
var xmlobj=new CreateNewObject();
if (xmlobj)
{
xmlobj.open("GET", "http://" + location.host + "/Website1/test.xml", true);
xmlobj.onreadystatechange=function()
{
if (xmlobj.readyState==READYSTATE_COMPLETE)
{
var ctrl=document.getElementById("ddlCustomers");
var doc=xmlobj.responseXML;
var countryname=ctrl.options[ctrl.selectedIndex].value;
var node=doc.selectSingleNode("//Countries/Country[CountryName='" + countryname + "']");
Error line here----> var details='Population: ' + node.selectSingleNode('Population/text()').nodeValue + '. Type of Government: ' + node.selectSingleNode('Government/text()').nodeValue;
document.getElementById("divResults").childNodes[0].nodeValue=details;
}
}
xmlobj.send(null);
}
}
</script>
For some reason I am getting the error above when I debug. I can't seem to see the problem. All it is is a string variable.
Some please help. Any would be appreciated.