Jump to content

simplexml xpath not working


ngreenwood6

Recommended Posts

I am trying to parse a blogspot feed using xpath but it doesnt seem to be working with anything that I try. I am not sure if it is because of the namespaces or what but I was hoping someone could help me. Here is the code:

 

        $xml = simplexml_load_file('http://feeds.feedburner.com/blogspot/MKuf');

   

    $next = $xml->xpath("//link[@rel=next]");

    print_r($next);

 

This is just returning an empty array and it should not be. I tried it doing just link or just entry and it still is returning empty. The only one I can run on it that works is *. Any help is appreciated.

Link to comment
Share on other sites

Since the XML document has a default namespace (for Atom), you need to tell XPath that it exists and in your query you need to ask for link elements within that default namespace. Since you're looking for only the next link of the feed (I'm guessing you don't want any from the entries) then there's also no need for // in the XPath query.

 

$xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$next = $xml->xpath("atom:link[@rel='next']");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.