开发者

Write to XML file using Objective-C

OK, I managed to read from an XML file using NSXMLParser, but now I don't know how to write to an XML file. I have an XML file, say:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<user id="abcd" password="pass1"/>
<user id="efg" password="pass2"/>
</root>

Now when a new user enters details, I want to store them in a new tag. Lets say like, the id is "hhhh" and password is "pass3".

I want to add a new tag with attributes as such:

<user id="hhhh" password="pass3"/>

to the XML file.

How should I do this? Please explain in an elaborate way. I am a newbie here. Any links to tutorials or examples will be muc开发者_如何学JAVAh helpful.

Thanks.


Check out the Tree-Based XML Programming Guide. You might use NSXMLDocument and friends. You could also search the web for open-source alternatives (there are plenty that parse and a few that write). A quick Google search for "using NSXMLDocument" yields several third-party tutorials.

It's better that you read the documentation yourself first and ask more specific questions. Help us help you. :-)


There's a number of really good third party XML parsers you can take a look at that will probably make it easier on you.

Here's a good post I found talking about them. http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project


Try using kissxml.

The goal is to create an NSXML style API that can used in environments without NSXML (e.g. iPhone).

KissXML was inspired by the TouchXML project, but was created to add full support for generating XML as well as supporting the entire NSXML API.

Please support this free and open source project

address

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜