NSURL *url = [[NSURL alloc] initWithString:@"..."];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
[xmlparser parse]
返回否。为什么会这样?
输出:错误错误错误!!!
答案 0 :(得分:1)
如果您在委托parseErrorOccurred:
课程中实施XMLParser
方法,它会为您提供错误的确切原因。
类似的东西:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"NSXMLParser ERROR: %@ - %@", , [parseError localizedDescription], [parseError localizedFailureReason]);
}