如何在文档中下载并保存xml,然后如何从文档中解析xml文件? [英] how to Download and save xml in documents and then how to parse xml file from documents?

查看:105
本文介绍了如何在文档中下载并保存xml,然后如何从文档中解析xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序应用程序中,我必须解析从Internet下载的xml文件。如何下载这个xml并保存在iphone上的文件中?然后我怎样才能开始解析保存在文档中的XML?

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??

推荐答案

你的意思是那样的

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]

这篇关于如何在文档中下载并保存xml,然后如何从文档中解析xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆