Take the 2-minute tour ×

I want to save data to xml file , which include

  • Create xml file
  • insert in it
  • delete from it
  • update certain node
  • read all the elements

any suggestion please , any sample tutorial code will be highly appreciated

share|improve this question
look into plist files –  Radu Jun 7 '11 at 8:53
can plist files save for example students nodes –  AMH Jun 7 '11 at 8:55
plist files have the structure of an xml file, or save it as an xml or text files –  Radu Jun 7 '11 at 10:04
i post my question here, if you want to continu to help me thank you FelixLam –  JioGray Oct 28 '11 at 9:07

3 Answers 3

up vote 3 down vote accepted
NSURL *url = [NSURL URLWithString:@"http://abcd.com/sample.xml"];
NSData *data = [NSData dataWithContentsOfURL:url];  // Load XML data from web

// construct path within our documents directory
NSString *applicationDocumentsDir = 
   [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample.xml"];

// write to file atomically (using temp file)
[data writeToFile:storePath atomically:TRUE];

If you are parsing the XML into an NSArray or NSDictionary, it is better to just save the array or dictionary so that you don't have to parse the data in the cache every time you want to read it. Both NSArray and NSDictionary have the methods writeToFile and initWithContentsOfFile

share|improve this answer

You can use .plist file for XML structured storing the XML. It works for me.

share|improve this answer
could u give me sample code –  AMH Jun 7 '11 at 9:08

Why do you want to use XML-files on the iPhone? There are more efficient ways to handle that data on the device. You might want to have a look at CoreData which supports SQLite and XML as persistent stores.

XML-Parsing is resource intensive especially if the XML gets very large. CoreData might be able to help you navigate around the hardware limitations of the iOS platform.

share|improve this answer

Your Answer


