How to load and save xml in documents, and then how to parse an XML file from documents?

In the application for the application, I need to parse an XML file downloaded from the Internet. How to download this xml and save documents on iphone? and how can I start parsing XML stored in documents?

+3
source share
2 answers

You mean something like this

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]
+4
source

Load the contents into the object the NSDatafirst time it is loaded. Save it to disk using one of

writeToFile:atomically:writeToFile:options:error:

NSData: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/instm/NSData/writeToFile:atomically:

, [NSData dataWithContentsOfFile:], NSData.

NSData XML, , , . NSString, XML Objective-C?

+3

Source: https://habr.com/ru/post/1752811/


All Articles