iPhone XML 解析问题
我是 iPhone 开发新手,我正在尝试解析此链接并将其放在我的表格视图上,但是当我的表格视图显示时,标题不会显示在行中。我在这里做错了什么?
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"RSS Feeds";
rssList = [[NSMutableArray alloc] initWithCapacity:1];
NSString *URLString = [[NSString alloc]initWithFormat:@"http://www.rpg.net/index.xml"];
NSLog(@"%@",URLString);
NSURL *xmlURL = [NSURL URLWithString:URLString];
NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[firstParser setDelegate:self];
[firstParser parse];
[URLString release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName compare:@"item"] == NSOrderedSame) {
[rssList addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
[attributeDict objectForKey:@"title"],@"title",
[attributeDict objectForKey:@"link"],@"link",
nil]];
}
}
I am new to iPhone dev and I am trying to parse this link and put it on my tableview, however when my tableview shows up, the titles do not show up in the rows. What I am doing wrong here?
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"RSS Feeds";
rssList = [[NSMutableArray alloc] initWithCapacity:1];
NSString *URLString = [[NSString alloc]initWithFormat:@"http://www.rpg.net/index.xml"];
NSLog(@"%@",URLString);
NSURL *xmlURL = [NSURL URLWithString:URLString];
NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[firstParser setDelegate:self];
[firstParser parse];
[URLString release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName compare:@"item"] == NSOrderedSame) {
[rssList addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
[attributeDict objectForKey:@"title"],@"title",
[attributeDict objectForKey:@"link"],@"link",
nil]];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用它从 rss feed 进行 xml 解析。
use this for xml parsing from a rss feed.