我有一个iPhone应用程序,可以从网址中进行XML解析。在我的资源目录(在XCode中)中有一个我想使用的sample.xml文件。
如何在代码中引用此文件?我尝试了@"sample.xml“作为网址,但它似乎无法找到它。
发布于 2009-12-15 08:44:14
首先,要小心将URL作为路径传递,反之亦然-您可能无法轻松地将两者互换。如有必要,请尝试在文件路径前加上file://前缀。
至于查找路径,可以使用NSBundle方法pathForResource:ofType:,如下所示:
NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"sample"
ofType:@"xml"];
NSString *xmlFileContents = [NSString stringWithContentsOfFile:xmlFilePath];https://stackoverflow.com/questions/1904527
复制相似问题