无法在PHP中使用XPath选择XML
我一直在尝试访问一些XML,如下所示:无法在PHP中使用XPath选择XML,php,xpath,Php,Xpath,我一直在尝试访问一些XML,如下所示: <feed xmlns:s="http://syndication.nhschoices.nhs.uk/services" xmlns="http://www.w3.org/2005/Atom"> <title type="text">NHS Choices - GP Practices Near Postcode - W1T4LB - Within 5km</title> <entry> <i
<feed xmlns:s="http://syndication.nhschoices.nhs.uk/services" xmlns="http://www.w3.org/2005/Atom">
<title type="text">NHS Choices - GP Practices Near Postcode - W1T4LB - Within 5km</title>
<entry>
<id>http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/27369</id>
<title type="text">Fitzrovia Medical Centre</title>
<updated>2011-08-20T22:47:39Z</updated>
<link rel="self" title="Fitzrovia Medical Centre" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/27369?apikey="/>
<link rel="alternate" title="Fitzrovia Medical Centre" href="http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=303A92EF-EC8D-496B-B9CD-E6D836D13BA2"/>
<content type="application/xml">
<s:organisationSummary>
<s:name>Fitzrovia Medical Centre</s:name>
<s:address>
<s:addressLine>31 Fitzroy Square</s:addressLine>
<s:addressLine>London</s:addressLine>
<s:postcode>W1T6EU</s:postcode>
</s:address>
<s:contact type="General">
<s:telephone>020 7387 5798</s:telephone>
</s:contact>
<s:geographicCoordinates>
<s:northing>182000</s:northing>
<s:easting>529000</s:easting>
<s:longitude>-0.140267259415255</s:longitude>
<s:latitude>51.5224357586293</s:latitude>
</s:geographicCoordinates>
<s:Distance>0.360555127546399</s:Distance>
</s:organisationSummary>
</content>
</entry>
</feed>
NHS选择-邮政编码W1T4LB附近的GP机构-5公里以内
http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/27369
菲茨罗维亚医疗中心
2011-08-20T22:47:39Z
菲茨罗维亚医疗中心
菲茨罗伊广场31号
伦敦
W1T6EU
020 7387 5798
182000
529000
-0.140267259415255
51.5224357586293
0.360555127546399
我一直在使用以下PHP代码尝试访问数据:
<?php
$feedURL = 'http://v1.syndication.nhschoices.nhs.uk/organisations/pharmacies/postcode/W1T4LB.xml?apikey=&range=5';
$xml = simplexml_load_file($feedURL);
$xml->registerXPathNamespace('s', 'http://syndication.nhschoices.nhs.uk/services');
$pharm_entries = $xml->xpath('//entry');
var_dump($pharm_entries);
foreach ($pharm_entries as $v)
{
print_r($v->nodeValue);
}
?>
registerXPathNamespace('s','http://syndication.nhschoices.nhs.uk/services');
$pharm_entries=$xml->xpath('//entry');
var_dump($pharm_条目);
foreach($v的pharm_条目)
{
打印($v->nodeValue);
}
?>
使用var\u dump
时,$pharm\u条目始终为空。出于某种原因,XPath没有返回正确的simplexmlement
,查询字符串保持原样。我希望当前的//entry
能够找到
节点的所有实例,但它没有
我怎样才能让它工作?另外,获取
标记并打印出地址的每一行(仍然使用XPath或其他方式)的最佳方式是什么
一如既往地感谢您的帮助。也尝试注册Atom命名空间:
$xml->registerXPathNamespace('a', 'http://www.w3.org/2005/Atom');
$pharm_entries = $xml->xpath('//a:entry');