XCode 6.1 iOS 8.1 crashing- NSXMLParser does not support reentrant parsing

2.3k views Asked by At

I met a problem with NSXMLParser. My source is run well in iOS7/XCode 5, but crashing in iOS8.1/XCode 6. Crashing error is:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSXMLParser does not support reentrant parsing.'

I tried with other solution in this post, but error still happened. Anyone can help me more?

My source like this

AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate, NSXMLParserDelegate>
{
    NSXMLParser *xmlParser_;
...
}

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self parseData];
    ....
}

- (void)parseData
{
    titleList_ = [[NSMutableArray alloc] init];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:fDetail ofType:fXML];
    if (filePath)
    {
        NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
        if (myText)
        {
            countPage_ = 2;
            NSData *xmlData = [myText dataUsingEncoding:NSUTF16StringEncoding];//NSUTF8StringEncoding];
            xmlParser_ = [[NSXMLParser alloc] initWithData:xmlData];
            xmlParser_.delegate = self;
            [xmlParser_ parse];

        }
    }
}
1

There are 1 answers

1
Priya Thiagarajan On

The same code works fine for me in iOS 8/XCode 6. Here is my code:

NSString *elementname;
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  [self parseData];
  return YES;
}

- (void)parseData
{
  titleList_ = [[NSMutableArray alloc] init];
  NSString *fDetail = [NSString stringWithFormat:@"sample"];
  NSString *filePath = [[NSBundle mainBundle] pathForResource:fDetail ofType:@"xml"];
  if (filePath)
  {
    NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    if (myText)
    {
      countPage_ = 2;
      NSData *xmlData = [myText dataUsingEncoding:NSUTF16StringEncoding];//NSUTF8StringEncoding];
      xmlParser_ = [[NSXMLParser alloc] initWithData:xmlData];
      xmlParser_.delegate = self;
      [xmlParser_ parse];

    }
  }
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
  elementname = elementName;
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
  elementname = elementName;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
  if([elementname isEqualToString:@"CatalogId"])
  {
      int64_t cId = [string longLongValue];
      NSLog(@"%lld",cId);
  }

}

@end