'null' is null or not an object Error

Last post 06-19-2009 9:27 PM by Juwar. 2 replies.

Sort Posts:

  • 'null' is null or not an object Error

    06-19-2009, 4:08 PM
    • Member
      99 point Member
    • Juwar
    • Member since 12-05-2005, 5:27 AM
    • Posts 130

     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.

  • Re: 'null' is null or not an object Error

    06-19-2009, 8:15 PM
    • Member
      531 point Member
    • Jim Wang
    • Member since 07-08-2008, 10:55 PM
    • Posts 94
    What line are you throwing on?
    Cheers,
    Jim Wang
    Microsoft (ASP.NET)
    http://weblogs.asp.net/jimwang
  • Re: 'null' is null or not an object Error

    06-19-2009, 9:27 PM
    • Member
      99 point Member
    • Juwar
    • Member since 12-05-2005, 5:27 AM
    • Posts 130

    Error line here----> var details='Population: ' + node.selectSingleNode('Population/text()').nodeValue + '. Type of Government: ' + node.selectSingleNode('Government/text()').nodeValue;

Page 1 of 1 (3 items)