Php hostip.info-使用SimpeXML解析API响应

Php hostip.info-使用SimpeXML解析API响应,php,xml,api,simplexml,Php,Xml,Api,Simplexml,我试图用解析的xml响应,但似乎无法正常工作 响应 <?xml version="1.0" encoding="ISO-8859-1" ?> <HostipLookupResultSet version="1.0.1" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://

我试图用解析的xml响应,但似乎无法正常工作

响应

<?xml version="1.0" encoding="ISO-8859-1" ?>
<HostipLookupResultSet version="1.0.1" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>12.215.42.19</ip>
   <gml:name>Sugar Grove, IL</gml:name>
   <countryName>UNITED STATES</countryName>
   <countryAbbrev>US</countryAbbrev>
   <!-- Co-ordinates are available as lng,lat -->
   <ipLocation>

    <gml:pointProperty>
     <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coordinates>-88.4588,41.7696</gml:coordinates>
     </gml:Point>
    </gml:pointProperty>
   </ipLocation>
  </Hostip>
 </gml:featureMember>

</HostipLookupResultSet>

这是Hostip查找服务
霍斯蒂普
不适用
12.215.42.19
伊利诺伊州糖林
美国
美国
-88.4588,41.7696
有人能帮我访问例如Hostip>ipLocation>pointProperty>Point>coordinates吗


提前谢谢

您可以访问数组之类的属性 比如(我不确定你的例子)

Hostip->ipLocation->gml['pointproperty']这里有两种方法(可以通过搜索在其他地方找到!)

XPath(一个非常基础的示例)

简单的XML(不那么简单)


可能是great的副本,我认为这会有所帮助:)OP不想获取属性,链接的文章也没有说明如何获取命名空间元素 Hostip->ipLocation->gml['pointproperty']
$coords = $xml->xpath('//gml:coordinates');
echo $coords[0];
echo $xml
    ->children('gml', TRUE)->featureMember
    ->children('', TRUE)->Hostip->ipLocation
    ->children('gml', TRUE)->pointProperty->Point->coordinates;