I want to save data to xml file , which include
我想将数据保存到xml文件中,其中包括
- Create xml file
- 创建xml文件
- insert in it
- 插入的
- delete from it
- 删除从它
- update certain node
- 更新某些节点
- read all the elements
- 阅读所有的元素
any suggestion please , any sample tutorial code will be highly appreciated
任何建议,任何样本指导代码都将非常感谢。
3 个解决方案
#1
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
如果您正在将XML解析为NSArray或NSDictionary,那么最好保存数组或字典,这样就不必每次读取缓存中的数据时都进行解析。NSArray和NSDictionary都有writeToFile和initWithContentsOfFile方法
#2
1
You can use .plist file for XML structured storing the XML. It works for me.
可以使用.plist文件进行XML结构化存储。它适合我。
#3
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.
为什么要在iPhone上使用xml文件?有更有效的方法来处理设备上的数据。您可能想看看CoreData,它支持SQLite和XML作为持久性存储。
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.
XML解析是资源密集型的,特别是当XML变得很大的时候。CoreData可能可以帮助您绕过iOS平台的硬件限制。
#1
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
如果您正在将XML解析为NSArray或NSDictionary,那么最好保存数组或字典,这样就不必每次读取缓存中的数据时都进行解析。NSArray和NSDictionary都有writeToFile和initWithContentsOfFile方法
#2
1
You can use .plist file for XML structured storing the XML. It works for me.
可以使用.plist文件进行XML结构化存储。它适合我。
#3
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.
为什么要在iPhone上使用xml文件?有更有效的方法来处理设备上的数据。您可能想看看CoreData,它支持SQLite和XML作为持久性存储。
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.
XML解析是资源密集型的,特别是当XML变得很大的时候。CoreData可能可以帮助您绕过iOS平台的硬件限制。