Jump to content

Starting XML Parser In A Method Possible?

iOS iPhone iPad Xcode XML Parser Programming Methods iOS 5 iPhone 4 iPad 3

  • Please log in to reply
2 replies to this topic

#1
LooN3y

LooN3y

    InsanelyMac Protégé

  • Members
  • Pip
  • 29 posts
is it possible to call/start XML parsing inside a method?



- (MasterList *)processWebService:(NSString *)urlItemNumber
{
    status = [[NSMutableString alloc] init];
    mySingleItem = [[MasterList alloc] init];
   
    [status appendFormat:@"http://store.leestools.com:90/ios12/n_ios.asmx/"];
    [status appendFormat:@"getiteminfo?scode="];
    [status appendFormat:@"%@", urlItemNumber];
   
    NSString *urlAddress = status;
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
   
    mySingleItem.masterDescript = @"Fake Descript";
   
   
    if (connection)
    {
	    self.responseData = [NSMutableData data];
	   
    }
    else
    {
	    NSLog (@"The connection failed");
    }
   
   
    return mySingleItem;
   
}


is it possible to call XML parsing somewhere in this method?


I'm making a split view APP, and i created a separate .h and .m files to put parsing in there because, basically I'm using XML parsing in my "master View controller (table view)" and populates my tableview with products, and I'm creating this object to call XML parsing for all the detail data for "detail view controller"


but the XML parsing doesnt get called right away, in which makes all my strings nil

#2
Poco

Poco

    InsanelyMac Plumber

  • Administrators
  • 1,495 posts
  • Gender:Male
  • Location:Canada
Firstly and foremost, hopefully you're using ARC or your code is leaking like a sieve ;).

And to the main point. The NSURLConnection initializer initWithRequest:delegate: makes an asynchronous url connection which must use the delegate methods to get the data. So if you are intending to/must parse the downloaded data in that method, you will need to use the synchronous variant sendSynchronousRequest:returningResponse:error:.

IMO, I would avoid using the synchronous variant as it is less flexible, a pretty good explanation here: http://www.cocoainth...s-asynchronous/ and also because it requires some threading to not block the main thread - something which you should try to avoid unless you have a very good plan.

So in short I would rethink that method and how you want to load the data. Hacky solutions now make for painful maintenance later ;).

#3
TH3L4UGH1NGM4N

TH3L4UGH1NGM4N

    (~_~)

  • Retired
  • 1,159 posts
  • Gender:Male
  • Location:Wonderland
  • Interests:(~_^)
+1 with the ARC hope you had the box ticked when you created your project initially. (Xcode should warn you about non dereferenced ivars though)

For the topic on hand, iPoco basically gave you your options and I'm backing the asynchronous method simply because when it comes to downloading, under normal circumstances you don't want to sync it which would require threading and more of a chance that the parsed data might not come through in the event that another thread crashes your app. (Things happen unexpectedly better not open the possibility for it) I personally wouldn't go for a hacky solution to download information via the Internet because I always look at the data being crucial and the odds of the data getting lost along the way due to the non standard way of getting files. You're probably better off going down the aync method although it's a little more cumbersome than sync, it's rewards are undoubtedly better.

Only thing that really comes to mind as a hacky like method off the top of my dome is using a Singleton macro which I've done on occasions but like I said when it comes to downloading data I don't like to take risks on that.

Just my two cents though.





Also tagged with one or more of these keywords: iOS, iPhone, iPad, Xcode, XML Parser, Programming, Methods, iOS 5, iPhone 4, iPad 3


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy