我正在尝试解析在线xml文档,但每次运行脚本时它似乎都会返回(null)。我的解析方法有什么问题?
@implementation ViewController
NSString *livescore;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://www.scorespro.com/rss2/live-soccer.xml"];
NSData* data = [NSData dataWithContentsOfURL:url];
NSXMLParser* parser = [[NSXMLParser alloc] initWithData: data];
[parser setDelegate:self];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"channel"]) {
livescore = attributeDict[@"title"];
NSLog(@"%@", livescore);
}
}