我正在尝试解析应用程序委托didFinishLaunchingWithOptions:
方法的 xml 提要:
//Parse XML Data
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://xxxxxxxxxxxxxxxxx/xml"]];//url is just fine :)
[xmlParser setDelegate:self];
BOOL parseState = [xmlParser parse];
if (parseState) {
NSLog(@"parse succeeded");
}else{
NSLog(@"parse failed");//Always parse failed, parse is always "NO"
}
委托协议方法(没有被调用):
#pragma mark - NSXMLParserDelegate
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
NSLog(@"parser:didStartElement:namespaceURI:qualifiedName:attributes:");
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"parser:foundCharacters:");
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"parser:didEndElement:namespaceURI:qualifiedName:");
}
当然,AppDelegate.h 符合NSXMLParserDelegate
协议:
@interface AppDelegate : UIResponder <UIApplicationDelegate,NSXMLParserDelegate>
我错过了什么?为什么不调用协议方法,为什么[xmlParser parse]
总是返回NO
?谢谢。