Handling RSS Tags with NSXMLParser for iPhone
- by MartinW
I've found the following code for parsing through RSS but it does not seem to allow for nested elements:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentImage forKey:@"media:thumbnail"];
The RSS to used is:
<item><title>Knife robberies and burglaries up</title>
<description>The number of robberies carried out at knife-point has increased sharply and burglaries are also up, latest crime figures indicate</description>
<link>http://news.bbc.co.uk/go/rss/-/1/hi/uk/7844455.stm</link>
<guid isPermaLink="false">http://news.bbc.co.uk/1/hi/uk/7844455.stm</guid>
<pubDate>Thu, 22 Jan 2009 13:02:03 GMT</pubDate><category>UK</category>
<media:thumbnail width="66" height="49" url="http://newsimg.bbc.co.uk/media/images/45400000/jpg/_45400861_policegeneric_pa.jpg"/>
</item>
I need to extract the "url" element from the "media" tag.
Thanks
Martin