Here is the code fragment of my iOS application:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *xmlURL = [NSURL URLWithString:@"http://ift.tt/1uTsoW1"];
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[xmlParser setDelegate:self];
[xmlParser parse];
[self loadData];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([currentElement isEqualToString:@"food"]) {
[self saveData:[attributeDict objectForKey:@"att"]];
}
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
NSLog(@"Start XML");
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"XML ERRROR");
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"[%@] Emlement Finish", elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"[%@]Element Found", string);
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@"XML Finish");
}
The program crashes at [xmlParser parse] in iOS8, but not in iOS7. Log showed "Start XML" only and program crashed afterwards.
The XML source is generated by another Java server program, which contains a Base64 encoded image in XML. XMLParser will not crash if the XML is at the size of 300KB or smaller.
I have also tried all the XMLParser solutions on StackOverflow, but in vain.
Thank you very much in advance.
No comments:
Post a Comment