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, Ed, biapar, Willr, Ingo, swaiba

RSS through RestfulService parse error

Go to End

4 Posts   1611 Views


Community Member, 150 Posts

17 February 2010 at 10:23am

Edited: 17/02/2010 10:26am

Hi there,

I'm using this piece of code to embed news to a site via RSS.

	// Accepts an RSS feed URL and outputs a list of links from it
	function RestfulLinks($limit) {
		$delicious = new RestfulService('');		
		$conn = $delicious->connect();
 		$result = $delicious->getValues($conn, "channel", "item")->getRange(0,$limit);
		$output = '';
		foreach ($result as $key => $value) {
			$output =  '<b>' . $value->pubDate . '</b>' . ' &ndash; ' . $description . ' <a class="thickbox" href="'.$value->link.'?KeepThis=true&TB_iframe=true&height=600&width=960">More...</a>';
		return $output;

This works perfectly, but sometimes I get the following error (and website is unavailable!):

Error: Uncaught Exception: String could not be parsed as XML
At line 217 in ......./public_html/sapphire/api/RestfulService.php 

It looks like temporarily there is something strange going on in the feed (in this case wrong formatted or unavailable RSS feed?). Is there a way to make sure that this error doesn't affect my complete site. Something like: if feed cannot be parsed: do nothing.

Help is more than welcome, thanks in advance!


Community Member, 712 Posts

18 February 2010 at 7:40am

Edited: 18/02/2010 7:40am

Exception handling?

try {
	// Code that might fail
} catch (Exception $e) {
	// Stuff to do if it fails.


Community Member, 150 Posts

18 February 2010 at 8:46am

I'm sorry, I started with SilverStripe as a designer... learning by the day. Thanks Hamish, I managed to get that implemented.


Community Member, 150 Posts

18 February 2010 at 8:54am

One question remains. As this worked before (parse errors started popping up a couple of days ago and I haven't been working on/updating this particular site), is there something wrong with this RSS feed that may be causing the parse error. Does anyone has an idea?

The feed URL is