I can query the description nodes in an RSS feed and return a result like this:
$xpath = new DOMXPath($xmlDoc);
$items = $xpath->query('/rss/channel/item/description/..');
foreach($items as $number => $item){}
But it returns nothing when I query the entry nodes from an Atom feed like this (in which I follow the same pattern as RSS’s above):
$xpath = new DOMXPath($xmlDoc);
$items = $xpath->query('/feed/entry/..');
foreach($items as $number => $item){}
What am I missing?
There is no RSS namespace, whereas Atom elements are in the following namespace:
You can see this by looking at your document’s
feedelement, which probably looks something like this:You need to register this namespace before querying for elements in it:
And then use the chosen namespace prefix in your expression: