如何将xml数据写入iphone中的plist文件?

时间:2011-08-12 09:20:29

标签: iphone xml plist

如何将xml数据写入iphone中的plist文件?我正在使用此代码 `我用这个代码
- (void)connectionDidFinishLoading:(NSURLConnection *)连接 {

NSString *thexml=[[NSString alloc] initWithBytes:[webdata mutableBytes] length:[webdata length] encoding:NSASCIIStringEncoding];
  NSArray *paths = NSSearchPathForDirectoriesInDomains

(NSDocumentDirectory, NSUserDomainMask, YES);


NSString *documentsDirectory = [paths objectAtIndex:0];

//make a file name to write the data to using the documents directory:

// NSString * path = [[NSBundle mainBundle] pathForResource:@“mySettings”ofType:@“plist”];     NSString * fileName = [NSString stringWithFormat:@“%@ / textfile.plist”,

                      documentsDirectory];

//create content - four lines of text

//NSString *content = @"One\nTwo\nThree\nFour\nFive";
NSString *content =thexml;
NSLog(@"%@",thexml);
//save content to the documents directory

[content writeToFile:fileName 

          atomically:YES 

            encoding:NSStringEncodingConversionAllowLossy 

               error:nil];

[self writePlist:1 fileName:thexml];     [thexml发布];     [连接发布];`

但我看到显示文件的plist文件是一个curuupted。请给我一个解决方案.... 提前谢谢

0 个答案:

没有答案