how to get the data from the following xml
:
<HostipLookupResultSet version="1.0.1" xsi:noNamespaceSchemaLocation="http://www.hostip.info/api/hostip-1.0.1.xsd">
<gml:description>This is the Hostip Lookup Service</gml:description>
<gml:name>hostip</gml:name>
<gml:boundedBy>
<gml:Null>inapplicable</gml:Null>
</gml:boundedBy>
<gml:featureMember>
<Hostip>
<ip>182.0.0.1</ip>
<gml:name>Private</gml:name>
<countryName>Private</countryName>
<countryAbbrev>PR</countryAbbrev>
<!-- Co-ordinates are available as lng,lat -->
<ipLocation>
<gml:pointProperty><gml:Point srsName="http://www.abc.net/xyz/srs/epsg.xml#4326">
<gml:coordinates>68.7833,30.4</gml:coordinates>
</gml:Point></gml:pointProperty>
</ipLocation>
</Hostip>
</gml:featureMember>
</HostipLookupResultSet>
following is what i was trying:
$userIpAddr = "test.xml";
$ipLink= new SimpleXMLElement($userIpAddr, NULL, TRUE);
$user_ip = $ipLink->xpath("/HostipLookupResultSet/Hostip/ip");
$user_country = $ipLink->xpath("/HostipLookupResultSet/Hostip/countryName");
foreach($user_ip as $ip)
{
foreach($user_country as $country)
{
echo $ip.'<br/>';
echo $country.'<br/>';
}
}
is this a correct way to access the data?? if isn't then please suggest me the way to access the asked data...