views:

61

answers:

2

In my app app i have to parsing a xml file downloaded from internet. How to download this xml and save in documents on iphone ? and then how can i start the parsing of XML saved in documents??

A: 

Download the contents to an NSData object when it's loaded for the first time. Save it to disk using either one of

– writeToFile:atomically:
– writeToFile:options:error:

Which are described in the NSData class reference here: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/instm/NSData/writeToFile:atomically:

When you want to load it from disk, use [NSData dataWithContentsOfFile:] to load it into an NSData object again.

As for parsing NSData into XML, look into other answers to this very, very common question, e.g. http://stackoverflow.com/questions/924389/xml-parsing-in-objective-c

Kalle
A: 

You mean something like that

NSString *URLString = @"http://www.example.com/XML/note.xml";
NSURL *URL = [NSURL URLWithString:
              [URLString stringByAddingPercentEscapesUsingEncoding:
               NSASCIIStringEncoding]];


NSData *dataXML = [NSData dataWithContentsOfURL:URL];

NSString *applicationDocumentsDir = 
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample.xml"];
[dataXML writeToFile:storePath atomically:TRUE];
    NSData *contenuto = [NSData dataWithContentsOfFile:storePath];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:contenuto]
Claudio
Doesn't look too shabby to me. What's wrong with it? (And please, update your answer and put a comment to my answer rather than answering your question -- I don't get notifications when you do that so I can't react.)
Kalle