如何在文档中下载和保存 xml,然后如何从文档中解析 xml 文件? [英] how to Download and save xml in documents and then how to parse xml file from documents?
本文介绍了如何在文档中下载和保存 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屋!
查看全文