Mith
Mith

Reputation: 150

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 much helpful.

Thanks.

Upvotes: 0

Views: 5870

Answers (3)

xhan
xhan

Reputation: 6297

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

Upvotes: 0

Thomas Alvarez
Thomas Alvarez

Reputation: 276

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

Upvotes: 0

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

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. :-)

Upvotes: 2

Related Questions