views:

761

answers:

1

I have an iPhone app that does XML parsing from a URL. I have a sample.xml file in my Resources directory (in XCode) that I'd like to use for testing.

How do I reference this file in code? I've tried @"sample.xml" as the URL and it doesn't appear to be able to find it.

+2  A: 

First off, be careful passing a URL as a path and vice-versa - you may not be able to readily interchange the two. If you must, try prefixing the path of the file with file://.

As for finding the path, you can use the NSBundle method pathForResource:ofType: as such:

NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"sample"
                                                        ofType:@"xml"];
NSString *xmlFileContents = [NSString stringWithContentsOfFile:xmlFilePath];
Tim