解析存储在iPhone应用程序的Documents目录中的XML文件 [英] Parsing an XML file stored in the Documents directory of an iPhone application

查看:103
本文介绍了解析存储在iPhone应用程序的Documents目录中的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSXMLParser有三种类型的init。

NSXMLParser has three types of init.

- > init

-> init

- > initWith Data

-> initWith Data

- > URL的initWithContents

-> initWithContents of URL

=>但我的xml文件是存储在应用程序的文档目录中,如何解析存储在Doc Dir的文件

=> But my xml file is stored at Application's Document directory, so how to parse a file which is stored at "Doc Dir"

提前致谢。

推荐答案

nsdata可以使用文件内容进行初始化。将initWithContentsOfFile实例方法与NSDAta一起使用,并将其提供给nsxmlparser的initWithData方法:

nsdata can be initialize with the contents of a file. Use the initWithContentsOfFile instance method with NSDAta and supply that to nsxmlparser's initWithData method:

NSString * filePath = [[NSBundle mainBundle] pathForResource:@"someFile"
                                                      ofType:@"xml"];
NSData * fileData = [NSData dataWithContentsOfFile:filePath];
NSXMLParser * parser = [NSXMLParser initWithData:fileData];

这篇关于解析存储在iPhone应用程序的Documents目录中的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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