codereviewanskquestions
codereviewanskquestions

Reputation: 13998

Objective C, NSXML parser delegate methods never get called

xmlParser = [[NSXMLParser alloc]initWithData:[xmlString dataUsingEncoding:NSASCIIStringEncoding]];
[xmlParser setDelegate:self];
[xmlParser parse];

I have this in ApplicaitonDelegate.m file and I am trying to parse an xml document in - didFinishLaunchingWithOptions method. I am implement the NSXML delegate in my header file but the delegate method never gets called..

Upvotes: 0

Views: 1197

Answers (1)

FKDev
FKDev

Reputation: 2286

You are using NSASCIIStringEncoding. Are you sure that your XML is ascii encoded ? If you don't know, try with NSUTF8StringEncoding. It's a better choice anyway because it "includes" ASCII.

Have you implemented the parseErrorOccurred delegate message ?

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError

If there is an error related to encoding, you should get an error, e.g.

NSXMLParser error=31 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 31.)"

Upvotes: 2

Related Questions