1

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

DOK
  • 32,337
  • 7
  • 60
  • 92
AMH
  • 6,363
  • 27
  • 84
  • 135
  • can plist files save for example students nodes – AMH Jun 07 '11 at 08:55
  • plist files have the structure of an xml file, or save it as an xml or text files – Radu Jun 07 '11 at 10:04
  • i post my question [here](http://stackoverflow.com/questions/7927202/how-to-save-iuimage-and-nsstring-which-are-generate-by-nsurl-load-from-a-xml-fil), if you want to continu to help me thank you FelixLam – JioGray Oct 28 '11 at 09:07

3 Answers3

4
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

Arvind
  • 543
  • 1
  • 5
  • 17
1

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

Arvind
  • 543
  • 1
  • 5
  • 17
0

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.

Felix Lamouroux
  • 7,414
  • 29
  • 46