【发布时间】:2011-06-09 20:58:53
【问题描述】:
下面是我设法使用此 xpath 打印内容的提要结构$xml->xpath('/rss/channel//item')
结构
<rss><channel><item><pubDate></pubDate><title></title><description></description><link></link><author></author></item></channel></rss>
但是我的一些文件遵循这种结构
<feed xmlns="http://www.w3.org/2005/Atom" .....><entry><published></published><title></title><description></description><link></link><author></author></entry></feed>
我猜这应该是获取条目内容的xpath
$xml->xpath('/feed//entry')
证明我错了。
我的问题是使用正确的 xpath 是什么?我还缺少其他东西吗?
这是代码
<?php
$feeds = array('http://feeds.feedburner.com/blogspot/wSuKU');
$entries = array();
foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$entries = array_merge($entries, $xml->xpath('/feed//entry'));
}
echo "<pre>"; print_r($entries); echo"</pre>";
?>
【问题讨论】:
-
/feed//entry 没问题(/feed/entry 也应该可以)。你到底得到了什么?什么不起作用?
-
//不是必需的(可以只是/),但该查询似乎对我有用... -
您是否在示例中遗漏了命名空间?
-
猜对了,应该是
<feed xmlns="http://www.w3.org/2005/Atom"> -
当
print_r是 Array ( ) 时我得到的。我已经用我使用的代码更新了我的问题