Showing posts with label simplexml. Show all posts
Showing posts with label simplexml. Show all posts

Finding the previous and next links using SimpleXml


If you find yourself in a situation where you need to page through a large feed of entries with SimpleXML, you can use the below snippet to retrieve the 'previous' and 'next' links:
// assuming you have read your XML string into the $sxml object
$links = $sxml->children('http://www.w3.org/2005/Atom'); 
foreach($links as $link) {
  foreach($link->attributes() as $key => $value) {
    if ($key == 'rel') {
      print "$key => $value\n";
    }
  }
}