tags:

views:

146

answers:

3

Hello

Im building a new version of an iPhone application and Im wondering if I should review how my app communicates with the server. My iPhone client sends and receives XML over HTTP requests.

To send the information I use ASIHTTPRequest framework. I "manually" build the XML request by appending strings.

To parse the response Im using a NSXMLParser.

My question is if I have better options to A) Create an XML string from a memory object. B) Create a memory object from the XML string.

Is there anything like JAXB to marshal XML into object?

Thanks Gonso

+1  A: 

I'm not entirely sure if this would work for you, but you could try using JSON along with a JSON parser such as SBJSON, which will create an object in memory for you based on the data.

To get JSON from an XML feed, I believe you could send the request for XML to YQL(http://developer.yahoo.com/yql) which can then translate the feed into JSON before sending it back.

Matt.M
Thanks for the answer. SBJSON looks like it could solve the problems, but I can't switch to JSON since there are other clients talking to the same server.
gonso
+1  A: 

Parsing XML

I cant think of something that looks for tags and parses things directly into objects (for XML), but a standard line-by line parser does the job. It does require a lot of code to use NSXMLParser, so just set up an external class to do it. It doesn't take that long, and is easy to cancel [parser abortParsing]

I basically used a model in which it starts a parent element, gets the the data from detail elements and then when the parent element closes, the parser takes the temporary data, fills an object with it, and adds the object to an array. It then repeats the process. I don't think my way would be very effective if you had more that 3 levels of XML (root==>parent tags==>details tags within parents), but it works for me. If you have complex XML, I would find some way to switch over to JSON and use SBJSON like Matt.M suggested. Creating XML

If I were creating XML, I would just use a bunch of for loops and one big NSMutableString.

ckrames1234
Thanks for the answer. Im already using the parsers, but I was looking for a more OO-like solution.
gonso
+2  A: 

Have a look TouchXml

http://code.google.com/p/touchcode/wiki/TouchXML

owen