我發現下面的代碼通過RSS解析,但它似乎不容許嵌套的元素:處理RSS標籤用的NSXMLParser爲iPhone
- (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"];
RSS來使用的是:
<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>
我需要從「媒體」標籤中提取「url」元素。
感謝 馬丁