我在计算此Feed中的总项目时遇到问题,
$xml = ('http://www.huffingtonpost.com/author/index.php?author=simon-cohen');
$xmlDoc = new DOMDocument();
$xmlDoc -> load($xml);
# Get and output "<item>" elements.
$x = $xmlDoc -> getElementsByTagName('entry');
# Count the total feed with xpath.
$xpath = new DOMXPath($xmlDoc);
$total_feed = $xpath->evaluate('count(//entry)');
echo $total_feed;
结果,
0
此Feed的内容是这样的,
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title>Simon Cohen</title>
<link href="http://huffingtonpost.com/author/index.php?author=simon-cohen"/>
<updated>2011-11-08T11:40:28-05:00</updated>
<author>
<name>Simon Cohen</name>
</author>
<id xmlns="http://www.w3.org/2005/Atom">
http://www.huffingtonpost.com/author/index.php?author=simon-cohen
</id>
<rights>Copyright 2008, HuffingtonPost.com, Inc.</rights>
<subtitle>HuffingtonPost Blogger Feed for Simon Cohen</subtitle>
<generator>Good old fashioned elbow grease.</generator>
<entry>...</entry>
<entry>...</entry>
</feed>
答案 0 :(得分:1)
得到了我的回答:
# get and output "<entry>" elements
$x = $xmlDoc -> getElementsByTagName('entry');
# Count the total feed with xpath.
$total_feed = $x->length;