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.

General Questions

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

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

Parse values and attributes from RSS feed


Reply

625 Views

Avatar
Imploosio

5 August 2011 at 3:30am Community Member, 5 Posts

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 [url=http://doc.silverstripe.org/sapphire/en/reference/restfulservice]RestfulService[/url] 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!