0

hi guys,i parse my file xml from my server

NSString *theXML = [[NSString alloc] initWithBytes: [Conn.webData mutableBytes] length:[Conn.webData length] encoding:NSUTF8StringEncoding];
    //NSLog(theXML);
    [theXML release];

but now i want download this file in my iPhone,it possible to do this?

i see this exemple but i not undersund :

NSString *path=[NSTemporaryDirectory() stringByAppendingString:@"file.txt"];

// save the people array
BOOL saved=[NSKeyedArchiver archiveRootObject:people toFile:path];
if(saved){
    //NSLog(@"saved");
}else{
    //NSLog(@"Not saved");
};

// reload array
people=[NSKeyedUnarchiver unarchiveObjectWithFile:path];
if(newArray==nil)
{
    // create new array
    people=[[NSMutableArray alloc] init];
}else{
    // retener los datos
    [perople retain];
};

1 Answers1

0

You can use NSData *data=[NSData dataWithContentsOfURL: options: error:] and [data writeToFile: options:1 error:]; for doing this.

aknew
  • 1,091
  • 7
  • 22
  • i want download file not parsing – Assouma Chikos Jul 07 '11 at 08:56
  • There is no parser, dataWithContentOfUrl download file from url into NSData and writeToFile save it into your iPod and no matter what the file is for the link - I downloaded small images this way, not only xml. NSString have metod writeToFile too – aknew Jul 07 '11 at 09:22
  • what u mean with option can u explain me please – Assouma Chikos Jul 07 '11 at 09:48
  • This is read-write files different options, better read more about them in the Xcode Help. There are similar methods without options like writeToFile:atomically: – aknew Jul 07 '11 at 10:02
  • i try this NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://127.0.0.1/webservice2/theflah.xml"]]; [data writeToFile:@"/Users/mediatun1/Desktop/chikos" atomically:YES]; – Assouma Chikos Jul 07 '11 at 10:04
  • but i not see theflah.xml in folder chikos – Assouma Chikos Jul 07 '11 at 10:05
  • my question haw i can create theflah.xml in my folder chikos – Assouma Chikos Jul 07 '11 at 10:15
  • I dont know, how can you write file in custom plase in iphone filesystem and not sure that it possible. I'm not sure iphone FS has folder /Users/mediatun1/Desktop too. – aknew Jul 07 '11 at 10:31