2009-01-22 67 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,希望它可能有一些用处。

我很想听听你的想法呢!