2

My Iphone communicates with my SOAP web service.

I have a questionnaire in my XML, which includes questions, their answers, and choices of some UI information..etc. So when the user enters a value for a set of questions using the IPhone and sends them back again to the Web service, the Service will add new unanswered questions to that XML.

So a conversation with the Web service starts with an empty XML and builds up to 200-300Kb of XML as the user answers the questions and receives new ones. Since it is a stateless Web Service, all the information will be kept in the XML.

Practically, I only need to find and parse the latest questions from the response XML, which should be good with a SAX parser, and modify only that part of the XML while adding the new answer and sending back again via the Web service the modified XML. BUT the user also should be able to click "Back". So that means I have to hold that XML in memory(200-300KB) and parse when necessary as the user clicks back and next.

My question is which approach is better:

1-Get the XML, parse it totally into objects with the DOM, release XML from memory and work only with the objects as the user clicks back and next. Then when it comes to sending it back, assemble a new XML message from scratch with my objects. Also this approach seems to reduce the clicking time

2-Use the SAX parser and only parse when I need to as the user clicks back and next. But then I have to hold all the XML in the memory. I do not know if Iphone can handle that, and back-next actions should take longer since I parse every time. But the good side is that I don't need to re-assemble an XML from objects again when I am done.

I think the second approach is better, what do you think? And which parser is good for this job?

Andrew Cowenhoven
  • 2,778
  • 22
  • 27
Spring
  • 11,333
  • 29
  • 116
  • 185

2 Answers2

1

Personally I prefer DOM XML parsers due to their ease of use and the ability to separate parsing/creating logic from the rest of the code. It seems that your application would be best suited to use a DOM parser because you said so yourself that sometimes you only need certain parts of the XML, not the entire document. SAX parsers do not support random read access.

FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82
  • So I can still use DOM and follow the second approach I mentioned above? also as far as I understand I do not need to re-construct an XML from scratch after I have done with editing my data, but simply only changing the necessary places that have been changed? if this is true lets say I parsed latest 10 questions from XML and fill my objects with data, then as user enter data I edited my data objects and finally I have to edit the correspending elements in the XML, DOM is good for this? and which objective-C objects can i use for this? – Spring Jun 21 '11 at 14:49
  • 1
    Yes, everything sounds fine. So do you have to return the same XML that you download? Upload speeds are slower and that could take a while. Don't you have some sort of ID used for the questions? If so, you could simplify the response to only send the ID of the question and the answers and the personal identification data. As for what objects to use, I would probably just create a simple object with properties for your data (questionId, questionText, etc.). – FreeAsInBeer Jun 21 '11 at 15:02
  • I will change a few element names, add values to the questions and send back, Web service is stateless, so I dont need to hold any info in server. But your Idea looks good that Web service always responds with the full XML and client responds with only the question and an answer, sure this will speed up the response time. but then I need to change a lot in the web service. Do you think it worths the effort? or by simply not parsing whole the XML but the necessary parts I can re-gain some seconds eneough to make it feel not slow? – Spring Jun 21 '11 at 15:18
  • 1
    It really depends on how large your audience is and how responsive they expect the application to be. Since you already have things set up to work a certain way I would continue with that until you have the features implemented that you need. Once you aren't being inundated with feature requests/progress updates then you can turn to increasing speed. There's no sense spending a great deal of time rearchitecting the application if the application's lifetime is limited. – FreeAsInBeer Jun 21 '11 at 15:21
  • Thanks, I think will go with the libxml2-dom then and I will parse when necessary. Im a java developer and new to Obj-C, finally I appreciate your recommendations which collection objects to use in Obj-C for this project. e.g using linkedhashmap vs hashtable kind of reccomendations if you have any. – Spring Jun 21 '11 at 15:30
  • I'm not versed in the performance implications of the different collection types, although I would go with whatever you are most comfortable with and whichever seems to make the most sense in the context of your data. `NSDictionary`s are frequently used for holding data in Obj-C. – FreeAsInBeer Jun 21 '11 at 15:33
  • tnx, I have another unanswered question maybe you can answer here http://stackoverflow.com/questions/6404325/need-help-on-objective-c-code-wsdl2objc-generated – Spring Jun 21 '11 at 16:35
0

read the following article and you will find the best solution for you http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project

I would go with NSXMLDocument nevertheless.

chewy
  • 8,207
  • 6
  • 42
  • 70
  • I think that speed is not an issue regarding your file size, both SAX and DOM will work almost flawlessly. that said the article contains a good speed comparison and vital information to your question. – chewy Jun 20 '11 at 14:01
  • My main question is not the parsing speed but the app design. Parse as the user clicks back, next or parse in advance everything and release the XML from memory.. – Spring Jun 20 '11 at 15:01