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 s
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. How do I parse an NSString containing XML in Objective-C?
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]