I've got an Objective-C/cocoa based application that I'm working on. This app is client<->server. Currently, the communcation protocol is based upon some fairly simple XML. While XML works for this task, it is not ideal in any aspect. It's a pain to serialize data to XML, it's not particularly light-weight, and difficult to incorporate non-data information (such as: 'do this next') in.
I'm looking for suggestions to an alternative.
I've considered some of the ones listed here, but haven't decided on any. Suggestions?
If you are talking to a Objective-C server you can look into encoding and decoding with the preferred serialization methods available in Objective-C.
NSKeyedArchiver and NSKeyedUnarchiver
Basically you will get an NSData from the NSKeyedArchiver that you will send (bytes/length) to the other part and there place it back into an NSData and use NSKeyedUnarchiver to unpack it into objects again.
I'm using JSON for an iphone application - I typically would prefer XML, but we needed it very lightweight, so we decided on JSON.
If your working with XML, you should take a look at XPath if you've not already - it will give you tremendous power for extracting values from a XML data structure.
What kind of server do you have? If the server is java based I'd recommend looking at HessianKit by Fredrik Olsson. Encode/Decode to ordinary Objective-C types and put in NSArrays and NSDictionaries will make the experience smoother.
What's wrong with (Portable) Distributed Objects?
Related
I'm not asking for a solution, but rather what topics I should be reading for the optimal solution for this problem?
I want to read whatever I have in my object graph and write it in an xml file.
I think I can fetch every object manually, read them and then write them to a file. But I dont think this is a good approach to this problem.
Can someone be my guidance?
Check out RestKit. It is meant for talking to server from iOS devices but it also works as an app and has a very powerful object model. You can probably abuse it to serialize your object.
I'm developing small application for iOs, and I have got a problem.
My application uses restful API, using post requests and as response it receives XML.
API has about 40 different methods, and problem is that I need to parse them all into objects. But, I want to implement all of the parsing in one class. I'm using NSXMLParser, and as far as I understand I must use different classes to use as a delegate for NSXMLParser.
Is there a way to do it one class?
If you are developing a small project and you want to avoid headaches, the best way to parse XML files is using ElementParser, simple and easy to use parser with examples in its webpage. With it, you can set different callbacks for different elements in the XML, so you can do all the parsing work in one class.
Also note that is free of charge only for personal use, and you have to pay a license if you plan to use it with commercial purposes.
I am doing Objective C programming and I want send and receive requests(Login/data fetching) over the client/server.
Now the problem is Should I do it using XML or any other Method.
Also I know nothing how to write XML for any particular website.
I am hassling for many days.Can anybody help?
XML particularly SOAP is very bloated and the support in Objective-C is severely lacking. I would recommend JSON for lightweight use and in fact Apple use it for their Push Notification server.
If you DO want SOAP then check sudzc.com for an online objective-c generator from a WSDL.
There's no such animal as "any particular website." Some return data in HTML, RSS, ATOM, or JSON format, others may use a custom XML schema all their own. Likewise with the data you send; they may expect requests via SOAP or HTTP, with any type and number of inputs the creators chose.
In short, you need to find out exactly what is expected by the one particular site with which you're trying to communicate, and give it what it wants. That's why programmers get paid the big bucks, because there's no easy "do what I mean" button. :-)
Your question is whether you should use xml or any other method of communication.
XML has been designed to standardize communication, which is especially handy for communicating between several parties, as the structure of the document can be formally written down in a document and can be validated, so there is no discussion afterwards about the syntax of the document.
Although that is a noble idea, XML is relatively complex and not as light weight as, for example, json.
As long as you are writing your own client that communicates to your own server, the protocol used between those 2 can be anything, and do not need to be XML.
Therefore I would suggest using a lightweight and easy to understand protocol. Json is gaining popularity due to its simplicity.
If you have control over the output of the data on your server, I'd suggest you output the data directly as a plist. Plists are native dictionary objects that can be directly instantiated with [NSDictionary dictionaryWithContentsofURL:].
Take a look at the PList programming guide for proper formatting.
We're deciding between using JSON vs. Property List (binary) for our API, which will be accessed by iPhone/iPad/iPod Touch.
Are there any speed advantages?
The server guys are going to understand JSON better.
Plists work really well and have much, much better type safety. The real issue you'll run into with JSON is someone server side adds a few quotes around a number and suddenly your app is crashing.
But, JSON is compact, easy to read (unlike binary plists), and as noted is really well understood. So just be very careful in the parsing code, and try out JSON.
According to Sam Soffes, JSON.
edit: he talks about xml-based plists, not binary plists. Either way, json will typically be easier to generate from web based api's.
I'm looking for a D template library to take an arbitrary variable and marshal it into a transportable bundle. The variable might be a basic value type (int, char[], real) or might be a struct or class and even might contain or be a reference type. A system that can do this without any per type help would be nice but I suspect that it's to much to ask so I'd be happy with something that uses light weight annotations.
If nothing like that exists suggestions on how to structure it would be nice. I can think of a few ways to do the sterilization but I'm not sure how to specify the annotations.
Background: After trying to use ASMX and WCF web services and not likening them I'm felling like I want to try my hand at the RPC problem.
edit: BTW I don't care to much what the format in the middle is (XML, JASON, YAML, binary) as long as it's portable.
Have a look at Google Protocol Buffers. Maybe you can use the C++ or C bindings directly, or write D bindings yourself.
Here's a basic one I wrote for D 1.x. It was written quite some time ago, so it might be possible to improve it, but it does work. The actual format is basically network byte-order binary, so it should be safe to store and transfer the bytes.
http://gist.github.com/100885
It doesn't support classes or arbitrary pointers. To do that properly, you'd want something which memorised what references it had already serialised. If you restrict yourself to value types, arrays and AAs, it'll do the job.
If you do want to extend it to support classes, my advice would be to require toStream and fromStream methods to be defined.
I recommend you write your own, as it's a useful exercise in templating and helps you adapt the serialization format to your specific requirements.
You might want to take a look at tools.serialize (http://dsource.org/projects/scrapple/browser/trunk/tools/tools/serialize.d) as a starting point.
[edit] SORRY! Didn't realize it was you! :D