0

I know how to load an XML from a URL. But now I need to load an XML file locally.

I searched the internet but only found how to load XML file from "Documents Directory" (i.e. NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"xml"];)

I don't know how to load XML file from Xcode navigator, like this: ScreenShot of Xcode

Please help.

Thanks.

Hyder
  • 1,163
  • 2
  • 13
  • 37
  • 1
    [How to load](http://stackoverflow.com/a/13062577/3408316) and [NSData to NSString](http://stackoverflow.com/questions/6411965/converting-nsdata-to-nsstring-in-objective-c) – Okhan Okbay Sep 19 '15 at 14:34
  • @pandarencodemaster My bad. Thanks for the links. I didn't know that this: `[[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"xml"]` actually gets the file from Xcode navigator as well! I thought it only looks into the particular folder in the app's sandbox. Pleas correct me if I'm wrong. – Hyder Sep 19 '15 at 14:44
  • 1
    Not as well, but only fetches files from your Bundle – Okhan Okbay Sep 19 '15 at 14:53

1 Answers1

0

Thanks to @pandaren codemaster for guiding me to the links he posted in the comment.

The code,

NSString *path = [[NSBundle mainBundle] pathForResource:@"adml" ofType:@"xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);

actually loads the adml.xml file from Xcode navigator locally, and converts into an NSString so we can verify the output too.

Problem solved.

Thanks again.

Hyder
  • 1,163
  • 2
  • 13
  • 37