How to write to an XML file from the iPad OS?

2019-06-06 18:44发布

问题:

I am developing an app for IPad, and I need to modify several attributes in a XML file at runtime.

I found the class NSXMLDocument, http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSXMLDocument_Class/Reference/Reference.html

But I haven't been able to import it to my project.

Is this class not available for IPhone/IPad development?

Is there some other approach I can consider?

I read about libxml library. Is it my answer or there is a better approach?

回答1:

NSXMLDocument is MacOS X Cocoa only. You have available on iPhone NSXMLParser, and several external libraries built on libxml2 - TouchXML, KissXML and a couple of others.

Note that KissXML supports writing XML.

Other XML libraries that have been suggested include the XML support from Google Data and VTD-XML.



回答2:

You are looking for a DOM XML parser, which is best for modification of XML documents. See for example this tutorial - without mapping to and from Model Objects - use the XPath.