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

发布于 2024-11-29 14:57:57 字数 1215 浏览 0 评论 0原文

如何将 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]; [xml发布]; [连接释放];`

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

how to write a xml data in to plist file in iphone? i am using this code
` i m use this code
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

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 release];
[connection release];`

but i m see the plist file that display a file is a curuupted .?? pls give me a solution ....
thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文