I agree. I just tried both answers and got good results. Here is the test code I just ran:
<?php
$url = 'http://api.hostip.info/?ip=87.14.94.152';
// $data = file_get_contents($url);
$xml = simplexml_load_file($url) or die("feed not loading");
// $Country = $xml->gml['featureMember']->Hostip->countryName;
// echo $Country;
echo 'BREAK HTML';
echo "-----";
echo "// "; var_dump($xml); echo " //<br/>";
?><br/><?php
var_dump($xml->gml);
?><br/><?php
print_r($xml);
?><br/><?php
var_dump((string) $xml->gml->featureMember->Hostip->countryName);
?><br/><?php
echo $xml->gml['featureMember']->Hostip->countryName;
$Country = (string) $xml->children('gml', true)
->featureMember->children('', true)
->Hostip->countryName; // => ITALY
echo $Country;
$fm=$xml->xpath('//gml:featureMember');
print_r($fm[0]->Hostip->countryName);
and here are the results output:
BREAK HTML-----// object(SimpleXMLElement)#1 (1) { ["@attributes"]=> array(1) { ["version"]=> string(5) "1.0.1" } } //
object(SimpleXMLElement)#2 (0) { }
SimpleXMLElement Object ( [@attributes] => Array ( [version] => 1.0.1 ) )
string(0) ""
ITALYSimpleXMLElement Object ( [0] => ITALY )
var_dump($xml)to the question.