views:

98

answers:

5

I am building and designing a (mostly) read-only interface to some data. I'll be uing ASP.NET MVC to build a psudo-restful API. I'm wondering if anyone can provide some resources for building full-client applications for various mobile platforms, iPhone, Android, Blackberry, Windows Mobile, etc.

I'm thinking that serving up XML data is going to be the most simple and universal, but parsing XML in objective-C for example doesn't sound like fun to me, but maybe there are some good libaries out there to help ease this task?

In other words, what formt will be the quickest to implement on the client side? Are there any JSON parsrs for iPhone or Android? I know there are .NET JSON parsers, but not sure about other platforms -- is ther another format that might better? Or should I stick with pure XML and deal with it on each platform differently?

A: 

I have worked with parsing XML on iPhone. If you are looking for a DOM parser, KissXML is a 3rd party library I suggest you go for. Its easy to use and the performance is good. If you are looking for a stream based parser, NSXMLParser classes in iPhone SDK would be good. JSON is considered more lightweight than XML and hence more suited for mobile devices. There are 3rd party library for JSON parsing for iPhone. You would need to google for them.

Hetal Vora
A: 

stick with pure XML and deal with it on each platform differently

That's really the only way forward. There is no magic cross-platform framework, and if there was it'd still be banned from the iPhone.

Will
A: 

Unless you've got a really good reason to use XML, use JSON. The vast majority of responses from a web-service can be adequately described using JSON, and there are a number of libraries (at least on the iPhone, I assume it's the same on Android et. al.) that allow you to parse JSON into native data structures in 2-3 lines of code.

On the iPhone platform, json-framework allows you to parse JSON with ease.

I guess the question is: Assuming that there is a JSON parsing framework for each client platform you are using, what advantage do you gain from using XML that justifies having to write more than 3 lines of code for parsing? For the majority of cases, there is no advantage.

Nick Forge
A: 

Use Json, all the mobile platforms have Json parsers. For Android, this may not be the most efficient solution, but it's probably the most pragmatic.

Android natively supports XML, but not Json. In other words, what I'm trying to say is that Android phones are equipped with an Hardware Accelerated XML Parser (their own dedicated little piece of silicon basically), but where it comes to Json parsing, Android phones don't have that, so they must use their CPU to do that work. In theory, this will mean that Android will use more CPU cycles, more energy, and therefore more battery, to parse Json, than to parse XML. That being said, don't fall into the trap of premature optimization, chances are, whatever difference there is will probably be insignificant to your use case scenario (and don't take my word for it, just use your profiler once your app is finished).

Stephan Branczyk
Can you give some information or pointers to the XML acceleration in hardware please? I have never heard of it before. Also never heard that ARM has xml accel IP.
piotr
+1  A: 

You could create a WCF REST Service that exposes the results in both formats, json and xml, and depending on the device, you could select the format that better fits the device capabilities. Also this is way better than creating and ASP.MVC "pseudo-restful API".

The WCF Service would look like this:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(
        Method = "GET",
        ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "DoWork/xml/{ID}/{Filter}")]
    void DoWork(int ID, string Filter);

    [OperationContract]
    [WebInvoke(
        Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "DoWork/json/{ID}/{Filter}")]
    void DoWorkJson(int ID, string Filter);
}

You can find a good example for creating a WCF Rest Service here.

iCe