views:

66

answers:

4

I am developing an application for iPhone and one part of it deals with a list of currencies and daily exchange rates. I am using SQLite to store all these rates.

Now I came to the part where I want to make the update part of my database with the new exchange rates.

The first thought was make a request to a server with a specific date and to read back an XML containing something like:

<date value="2010-10-04">
  <currency name="EUR" rate="xxx" />
  <currency name="USD" rate="yyy" />
  <currency name="GBP" rate="zzz" />
........
</date>
<date value="2010-10-05">
  <currency name="EUR" rate="xxx" />
  <currency name="USD" rate="yyy" />
  <currency name="GBP" rate="zzz" />
........
</date>

But now I was thinking isn't it better to make my own format, something like:

#|2010-10-04#EURxxx#USDyyy#GBPzzz#|2010-10-05#EURxxx#USDyyy#GBPzzz##

The separator will be #. Known that always the date takes 11 characters and starts with | and currency code takes 3 characters, I can search the rate until I will find a # sign.

Because I want to send as little data as I can I think this second approach will be better than the usual XML, even if I reduce the XML to:

<d v="2010-10-04">
  <c name="EUR" r="xxx" />
  <c name="USD" r="yyy" />
  <c name="GBP" r="zzz" />
........
</d>
<d v="2010-10-05">
  <c name="EUR" r="xxx" />
  <c name="USD" r="yyy" />
  <c name="GBP" r="zzz" />
........
</d>

What are your pro & cons for this?

+2  A: 

The pros:

  • As you already stated, it is shorter, faster to retrieve.
  • Faster to parse as well

The cons:

  • If you develop the server side and the other developer on the mobile side, then he may get confused when there are no meanings

  • It is hard to scale when you have more and more attributes and if you delete or change some attributes, you have to go over all codes to change it.

vodkhang
I am developing both mobile and server side. Also I may not have the exact attributes every time, that's why I will parse and find my rates based on the # sign and not necessary by a fixed position.
Parkyprg
+3  A: 

XML is easier to read and parse. Unless you're fetching a zillion currencies and daily rates a day, the # of bytes shouldn't be an issue.

Jordan
I have done some tests and using XML the data generated for 1 day has 830b and using the other format it is only 310b. If the user makes an update for a lot of days behind, the data sent will be three times less and being on a phone I think it counts. Thank you for your response.
Parkyprg
At the margins, this is still immaterial, since they both can be delivered in one packet. In the end, you have your answer. There's no right or wrong here, just options.
Jordan
+3  A: 

JSON format would split the difference between a proprietary format and a standard format. It is somewhat less verbose than XML and has the flexibility and maintainability vodkhang rightly expects.

Tim
+1 JSON is indeed lightweight
Henrik P. Hessel
+1  A: 

CFPropertyList is pretty good if you're using PHP as your server-side language. Easy to integrate with your server code and has built in support in iOS (e.g. an NSDictionary can be created directly from a plist file).

Link: http://code.google.com/p/cfpropertylist/

Jimmeh