作为初学者,我已经阅读NSXMLParser
并尝试实现一个解析器来解析 xml
<?xml version="1.0" encoding="UTF-8"?>
<a>Some text here</a>
我的实现
-(OneNodeXMLParser*)initOneNodeXMLParser{
appDelegate = (OneNodeXMLParser*)[[UIApplication sharedApplication]delegate];
return self;
}
-(void)parser:(NSXMLParser*) parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSLog(@"%s",__PRETTY_FUNCTION__,nil);
if([elementName isEqualToString:@"a"]){
// init some varibles
}
NSLog(@"Starting processing");
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"%s",__PRETTY_FUNCTION__,nil);
NSLog(@"%s",string);
}
-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"%s",__PRETTY_FUNCTION__,nil);
NSLog(@"Finishing processing");
}
我应该修改什么才能成功解析文件?