Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-24-2009, 09:01 AM   #2 (permalink)
Seidr
New Member
 
Join Date: Jun 2009
Posts: 6
Default

Quote:
Originally Posted by Miles View Post
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

Last edited by Seidr; 06-24-2009 at 09:04 AM.
Seidr is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,966
Threads: 38,751
Posts: 170,022
Top Poster: smasher (2,560)
Welcome to our newest member, cruisetom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.