如何将 xml 数据写入 iphone 中的 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]; [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论