Yasin Babahanoglu
Yasin Babahanoglu

Reputation: 33

How to cache or store parsed xml file?

My app parses an xml file from my server, but I want to store parsed xml file and next start of my app, controller initially should load stored xml file, then controller should parse it again to check that there may be an update I did on xml file, if there is, new elements parsed should also be stored again.

I am referring to those app such as magazines, newspaper apps. When you open those kind of apps, it loads stored data that was downloaded previous session. Yet, after it loads, it starts to update the data, and it stores new update again.

Where do I start? What do you guys suggest?

Thanks in advance...

Upvotes: 1

Views: 608

Answers (3)

Ted Xu
Ted Xu

Reputation: 1093

either CoreData or SQLite can do the trick

Upvotes: 0

sudo rm -rf
sudo rm -rf

Reputation: 29524

It's actually quite easy to store to the documents directory. For example:

NSData *data; //this is your xml file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString *filename = [NSString stringWithFormat:@"test.xml"];
NSString *path = [docs stringByAppendingPathComponent:filename];
[data writeToFile:path atomically:YES];

Then to retrieve it later, you can get the path like above, but retrieve the file instead of writing it:

NSData *data = [NSData dataWithContentsOfFile:path];

Upvotes: 0

ARC
ARC

Reputation: 1804

You can use CoreData or SQLite (use Objective-C wrapper FMDB https://github.com/ccgus/fmdb) to persist your XML. Then update the database everytime you see a unique id. Depends on how your XML data is.

Upvotes: 2

Related Questions