使用适用于iPhone的NSXMLParser处理RSS标记
我发现了以下通过RSS解析的代码,但它似乎不允许嵌套元素:使用适用于iPhone的NSXMLParser处理RSS标记,xml,cocoa-touch,Xml,Cocoa Touch,我发现了以下通过RSS解析的代码,但它似乎不允许嵌套元素: - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ NSLog(@"ended element: %@", elementName); if ([elementName is
- (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>
刀劫案和入室盗窃案上升
最新的犯罪数据显示,持刀行劫的数量急剧增加,入室盗窃也在增加
http://news.bbc.co.uk/go/rss/-/1/hi/uk/7844455.stm
http://news.bbc.co.uk/1/hi/uk/7844455.stm
2009年1月22日星期四13:02:03 GMTUK
我需要从“media”标签中提取“url”元素
谢谢
Martin当元素启动时,您需要获取属性(包括URL):
parser:didStartElement:namespaceURI:qualifiedName:attributes:
您需要在元素启动时获取属性(包括URL):
parser:didStartElement:namespaceURI:qualifiedName:attributes:
正如August指出的,您必须使用didStartElement来获取标记的属性。属性作为字典返回,属性名称作为键,属性值作为值。正如August指出的,您必须使用didStartElement来获取标记的属性。属性以字典的形式返回,属性名称作为键,属性值作为值。我刚刚发布了一个开放源码,希望它能有所用处
我也很想听听你的想法 我刚刚发布了一个开源软件,希望它能有所用处 我也很想听听你的想法