2009-01-22 80 views
1

我發現下面的代碼通過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」元素。

感謝 馬丁

回答

5

你需要得到的屬性(包括URL),當元素開始:

parser:didStartElement:namespaceURI:qualifiedName:attributes: 
0

截至8月指出的那樣,你將不得不使用didStartElement去屬性的標籤。屬性作爲字典返回,其屬性名稱作爲鍵和屬性值作爲值。

0

我剛剛發佈了一個開源的RSS/Atom Parser for iPhone,希望它可能有一些用處。

我很想聽聽你的想法呢!