Parsing an XML file stored in the Documents directory of an iPhone application

人盡茶涼 提交于 2020-01-13 08:58:32

问题


NSXMLParser has three types of init.

-> init

-> initWith Data

-> initWithContents of URL


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

Thanks in advance.


回答1:


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];


来源:https://stackoverflow.com/questions/1324404/parsing-an-xml-file-stored-in-the-documents-directory-of-an-iphone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!