Web Analytics Made Easy -
StatCounter issues with accessing nodes of xml file. - CodingForum

Announcement

Collapse
No announcement yet.

issues with accessing nodes of xml file.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • issues with accessing nodes of xml file.

    I have had no problem in the past using my code but today I notice that it is failing and I can not figure out why. I have tried different ways to access the xml nodes but none are working. The original method I used that worked before was using the ->xxx

    echo($geoLocXML->isp . '<br>');



    These are the errors I get...

    Notice: Trying to get property of non-object in /home/***/public_html/getGeoLocXML.php on line 20

    Notice: Use of undefined constant city - assumed 'city' in /home/***/public_html/getGeoLocXML.php on line 21

    Notice: Use of undefined constant countryname - assumed 'countryname' in /home/***/public_html/getGeoLocXML.php on line 22


    Can anyone tell what they think might be wrong with my code.

    Code:
    <?php				//exit;
    
    error_reporting(-1);
    
    //$ip = $_SERVER['REMOTE_ADDR'];
    //$geoLocXML = getGeoLocXML($ip); //->result[0];
    //$geoLocXML = file_get_contents('http://api.geoiplookup.net/?query='.$ip);
    $getGeoLocXML = simplexml_load_file('http://www.mysite.com/getGeoLocXML.xml');
    
    /*
    $getGeoLocXML = '<?xml version="1.0" encoding="iso-8859-1"?		>
    <ip>
    <results><result><ip>123.123.123.123</ip><host>123.123.123.123</host><isp>Provider</isp><city>My City</city><countrycode>GB</countrycode><countryname>United Kingdom</countryname><latitude>123.123</latitude><longitude>-1.123</longitude></result></results>
    </ip>
    ';
    */
    
    $geoLocXML = $getGeoLocXML->result[0];
    echo($geoLocXML . '<br>');
    echo($geoLocXML->isp . '<br>');
    echo($geoLocXML[city] . '<br>');
    echo($geoLocXML[countryname] . '<br>');
    
    /*
    <results>
    <result>
    <ip>123.123.123.123</ip>
    <host>123.123.123.123</host>
    <isp>Provider</isp>
    <city>My City</city>
    <countrycode>GB</countrycode>
    <countryname>United Kingdom</countryname>    
    <latitude>123.123</latitude>
    <longitude>-1.123</longitude>
    </result>
    </results>
    */
    ?>
    XML
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    
    <ip>
    <results><result><ip>123.123.123.123</ip><host>123.123.123.123</host><isp>Provider</isp><city>My City</city><countrycode>GB</countrycode><countryname>United Kingdom</countryname><latitude>123.123</latitude><longitude>-1.123</longitude></result></results>
    </ip>
    Last edited by needsomehelp; Sep 22, 2016, 12:10 PM.

  • #2
    XmlDocument doc = new XmlDocument();
    doc.Load("C:\\Books.xml");
    XmlElement root = doc.DocumentElement;
    XmlNodeList nodes = root.SelectNodes("/NewDataSet/booksdetail");

    foreach (XmlNode node in nodes)
    {
    string pages = node["pages"].InnerText;
    string description = null;
    if(node["Description"]!= null)
    {
    description = node["Description"].InnerText;
    }
    }
    Last edited by vinyl-junkie; Sep 30, 2016, 05:10 PM. Reason: signatures only allowed through the control panel

    Comment

    Working...
    X