Contando el artículo total en un feed ATOM

I have a problem in counting the total items in this 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;

resultado,

0

The content of this feed is like this,

<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>

preguntado el 08 de noviembre de 11 a las 17:11

1 Respuestas

got my answer:

# get and output "<entry>" elements
    $x = $xmlDoc -> getElementsByTagName('entry');

    # Count the total feed with xpath.
    $total_feed = $x->length;

respondido 09 nov., 11:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.