Quote:
Originally Posted by Miles
Hello all,
I'd like to be able to parse a local XML file, rather than one hosted out on the web somewhere. I followed the example found here: Parsing XML Files - iPhone SDK Articles but was unsuccessful in modifying the project to read a local file. Any help would be greatly appreciated.
Once I get that working, I'd like to be able to import XML files into an app. Preferably by emailing the file and opening the attachment on the iPhone. Is this doable, and if so, are there tutorials and/or documentation that someone can point out?
Thanks in advance!
|
Try this:
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:[NSData datawithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.xml"]]]
That will take the contents of the XML file 'test.xml' in the local bundle, and load it as an NSXMLParser object.
Alternatively, to take a file from the Applications 'Documents' directory, use the following to set the path:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory,NSUserDomainMask,YES);
NSString *xmlPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"test.xml"];
Hope this helps.
Seidr