views:

787

answers:

6

My app is made up of a TabBarController, each tab with a UITableView.

On launch I parse an XML file from my server into an Object class and then display the objects in the first tableview.

My question is, what do I do when I want to parse a second XML file? Currently, when doing so, the information in "XML-file-2" will overwrite the objects parsed by "XML-file-1". How do I go about this properly? Do I set up another Object class for each XML file or is there another to work around the issue?

I am using NSXMLParser.

A: 

... Don't overwrite the data that's already there...?

If you're displaying the contents in a UITableView, then I'd be willing to bet you've got an NSArray in there somewhere. Hopefully, if you've set this up properly, the NSArray contains model objects, each one of which corresponds to one row in your UITableView. However, I would suggest using NSMutableArray. Then when you parse the second XML file and build your model objects out of that, just use NSMutableArray's addObject: method and then reloadData on the UITableView.

Dave DeLong
Here's a code snippet from Parser.m file:http://pastie.org/537227Any comments welcome...
Canada Dev
@Canada Dev - it looks OK to me. Is it not working? When you create the NSXMLParser are you remembering to set this XMLParser object as the delegate?
Dave DeLong
Yeah, everything should be set correctly in my AppDelegate: http://pastie.org/538494
Canada Dev
+1  A: 

on line 21 of that snippet ( http://pastie.org/537227 ) you are setting the products array (appDelegate.products)to a new mutable array. if you want the second run to append to appDelegate.products, you should see if appDelegate.products already has objects in it, if so, don't assign a new array to it, just add to them to it using NSMutableArray's addObject: method

ctshryock
+1  A: 

I think you should consider having two instances of XMLParser, one for each XML file you want to read. It allows you to read as many XML files concurrently without affecting each other. It is also more modular.

notnoop
That's what my initial thought was for the best approach to solving the issue; setting up several Object classes to hold the objects from each XML I parse and then each have XML to parse the file.
Canada Dev
By the way. I ended up making a XMLParser super class and then divided the XML-file-specifics code in the XMLParser-subclasses. Works great.Also, I made sure to do a performSelectorInBackground so it parses in the background and doesn't feel like it's stuck between the tabs.
Canada Dev
A: 

Hi,

I'm new to iPhone objective c programming and in my app are struggling with calling multiple webservices. I read your comment about your solution for creating a super class for this. Can you please help me out with some sample code?

Tom

A: 

Can you share the final working code? Did you use two seperate AppDelegate files or one?

Hokie1200
A: 

As notnoop already mentioned, to make multiple NSXMLParser instances would be the best solution.
A open source iPhone RSS reader called Simple RSS Reader would be a good sample of what you want now.
You might use RSSParser class of the Simple RSS Reader as it is.

HTH

tomute