21493 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 930 Views |
-
RSS through RestfulService parse error

17 February 2010 at 10:23am Last edited: 17 February 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('http://www.cnbc.com/id/19811193/device/rss/rss.xml');
$conn = $delicious->connect();
$result = $delicious->getValues($conn, "channel", "item")->getRange(0,$limit);
$output = '';
foreach ($result as $key => $value) {
$output = '<b>' . $value->pubDate . '</b>' . ' – ' . $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.phpIt 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!
-
Re: RSS through RestfulService parse error

18 February 2010 at 7:40am Last edited: 18 February 2010 7:40am
Exception handling?
try {
// Code that might fail
} catch (Exception $e) {
// Stuff to do if it fails.
} -
Re: RSS through RestfulService parse error

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.
-
Re: RSS through RestfulService parse error

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 http://www.cnbc.com/id/19811193/device/rss/rss.xml
| 930 Views | ||
|
Page:
1
|
Go to Top |


