是飼料我設法使用此XPath
$xml->xpath('/rss/channel//item')
說要把我逼瘋了簡單的XPath問題
結構打印內容
<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 //輸入正常(/ feed/entry應該也可以)。你究竟得到了什麼?什麼不行? – unbeli 2011-06-09 21:03:06
'//'不是必須的(它可以只是'/'),但是這個查詢似乎對我有效...... – lonesomeday 2011-06-09 21:03:12
是否存在您已經不在示例中的名稱空間? – 2011-06-09 21:04:08