0
我正在尝试阅读和解析RSS提要。 RSS提要的标题是:如何获取getElementsByTagNameNS内容?
<rss version="2.0" xmlns:content="http://www.mywebsite.com" xmlns:media="http://search.yahoo.com/mrss/" >
我成功地检索既<title>
和<link>
从项目,但我似乎无法找到一种方法来检索<content:encoded>
孩子的。这就是我tryed至今:
<?php
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
....
$x=$xmlDoc->getElementsByTagName('item');
foreach($x as $item) {
$link = $item->getElementsByTagName('link')->item(0)->nodeValue;
$title = $item->getElementsByTagName('title')->item(0)->nodeValue;
$content = $item->getElementsByTagNameNS('http://www.mywebsite.com', 'encoded')->item(0);
echo ("<p><a href='" . $link. "'>" . $title . "</a></p><p>" . $content . "</p>");
}
?>
你可以想像$content
是空的,即使我试图让nodeValue
属性,我缺少什么吗?
你需要reeinvent轮?为什么不使用SimplePie来解析RSS? –
我的服务器位于代理之后,SimplePie允许我在请求期间设置它吗?无论如何,我在这里使用DomDocument,我不认为我是在重新发明轮子。 – raz3r
当我说重新发明轮子时,我的意思是你需要从头开始编写所有的代码才能获得这些值。我从来没有用代理测试SimplePie,但我认为这是可能的。看看它[链接](http://www.simplepie.org/) –