I am currently updating my app so that it utilizes the tools in the current SDK and I was wondering if there was a better way to asynchronously parse xml than this way:
NSOperation queue is a property in fileA.h
Code:
fileA.m
queue = [[NSOperationQueue alloc] init];
RequestOperation *request = [[RequestOperation alloc] initWithRequestString:requestString];
[queue addOperation:request];
[request release];
RequestOperation.m
- (id)initWithRequestString:(NSString *)str
{
if( ![super init] )
return nil;
self.requestString = str;
return self;
}
- (void) main
{
NSURL *url = [NSURL URLWithString:requestString];
NSData *dataXml = [[NSData alloc] initWithContentsOfURL:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:dataXml];
[dataXml release];
......
[fileA performSelectorOnMainThree:@selector(startParsing:) withObject:xmlParser waitUntilDone:YES];
[xmlParser release];
}
- (void) dealloc {
[requestString release];
[super dealloc];
}
This isn't all the code, but it shows the general form of how I was parsing xml before. The call to startParsing in fileA begins parsing the document using parserDidStart, parserFoundCharacters, parserDidStartElm etc.