how to Download and save xml in documents and then how to parse xml file from documents?

前端 未结 2 1079
难免孤独
难免孤独 2021-01-01 05:55

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

2条回答
  •  猫巷女王i
    2021-01-01 06:27

    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]
    

提交回复
热议问题