views:

158

answers:

1

Hi, is there any easy way of store XML data into core data?

Currently, my app just pulls the values from the XML file directly, however, this isn't efficient for XML files which holds over 100 entries, thus storing the data in Core Data would be the best option. XML file is called/downloaded/parsed ever time the app opens.

With the Core Data, the XML data would be downloaded ever 3600 seconds or so, and refresh the current data in the core data, to reduce the loading time when opening the app.

Any ideas on how I can do this?

Having reviewed the developer documentation, it doesn't look very tasty.

+1  A: 

I take that you mean you have to down load an xml file, parse it and then save the data encoded in the file? You have several options for saving such data.

If the data is relatively simple and static e.g. a repeating list of items, then you might just want to use a NSArray, NSSet or NSDictionary (or some nested combination) and then just write the resulting collection to disk as a plist using the collection classes writeToFile: methods. Then when the data is needed you just use one of the initWithFile: methods. The disadvantage of this system is that you have to read the entire file back into memory to use it. This system doesn't scale for very large data sets.

If the data is complex e.g. a bunch of separate but highly interrelated chunks of data, and moderately large, then Core Data would be better.

Of course, you always have the option of writing the downloaded file straight to disk as a string if you want.

TechZen