Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2011, 08:38 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 84
BrendanF is on a distinguished road
Default Best Way to Parse XML Asynchronously

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.
BrendanF is offline   Reply With Quote
Old 09-09-2011, 08:47 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

It seems like all you are trying to do is download the file, and then do the parsing on the main thread.

You should look at NSURLConnection (or ASIHttpRequest, a good wrapper).
smithdale87 is offline   Reply With Quote
Old 09-09-2011, 11:04 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 84
BrendanF is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
It seems like all you are trying to do is download the file, and then do the parsing on the main thread.

You should look at NSURLConnection (or ASIHttpRequest, a good wrapper).
If I were to do the parsing in RequestOperation.m, would this make the parsing separate from the main thread?
BrendanF is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 414
11 members and 403 guests
apatsufas, Eclectic, fiftysixty, JackReidy, jeroenkeij, Sami Gh, teebee74, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:59 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0