Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Parse values and attributes from RSS feed


Go to End


1475 Views

Avatar
Imploosio

Community Member, 5 Posts

5 August 2011 at 3:30am

Hello you'se,

I'm using RestfulService to parse in an external RSS feed, just a really simple list of news items with header and a link. On the XML I'm parsing, I have mix of values and attributes. I can get the headers and everything else I need with this snippet of code from RestfulService reference tutorial:

function ParseFeed($url){
    $rss = new RestfulService($url);
    $conn = $rss->request()->getBody();
    $result = $rss->getValues($conn, "entry");
    $output = '';
    foreach ($result as $key => $value) {
      $output .=  '<li><a href="'.$value->link.'">'.$value->title.'</a>';
    }
    return $output;
}

This returns the title but leaves the URL blank -- because it is href attribute on the 'link' node instead of value data. How should I go about getting the href attribute for my links? I suspect I need to use some combination of getValues and getAttributes, but I don't really have any clue how. Any help is highly appreciated!