Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-24-2009, 10: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 10:04 AM.
Seidr is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,626
Threads: 89,143
Posts: 380,333
Top Poster: BrianSlick (7,110)
Welcome to our newest member, vhenziel8
Powered by vBadvanced CMPS v3.1.0

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