Alessandro
Alessandro

Reputation: 4110

Create an XML file to save app data

I am creating an app where there is a page which enables users to create a small project, I mean painting with the brush, adding labels, text fields, and adding UIImageViews and placing an image in them using the iOS library. then a screenshot is taken (for now) and it is uploaded on dropbox. from a tableview the users will be able to see all the uploaded documents. but the point is that it is only a screenshot. I wanted to upload things in a way that the textfields could be scrolled, and when I add the video feature, see the video. then add comments. I thought of uploading all the images, photos, textviews separately, and then save all the position of the pieces in an XML, so that the projects can be viewed from the table view: when a row is selected the app opens the XML and in base of that composes all the pieces like a puzzle. I decided to use Google library, (data), but I can't seem to find where to download the sample project with the library. so I put it at a side. I then tried to use NSXML parser, but I only see tutorials that enable asccess to an xml file, not actually create one according to each project!! Help!! How can I proceed? Any suggestions or tutorials? May be were to give me the link to data project, and please not to the google developer page or trunk, because it is a mess!!

thanks for the help in advance

Upvotes: 1

Views: 7666

Answers (2)

Lloyd Sargent
Lloyd Sargent

Reputation: 614

OR you could use the very simple, very easy to use standard NSPropertyListSerialization:dataWithPropertyList:format:options:error and this is how you would do it:

Populate it with NSArray's and NSDictionary's (this is the part that requires the most code - but it isn't difficult to do). The objects in your dictionary are the children and sub children (which may be NSArray's of NSDictionaries). Then use the following to write it out:

NSData *xmlData = [NSPropertyListSerialization dataWithPropertyList: resultLists
                                                             format: NSPropertyListXMLFormat_v1_0
                                                            options: 0
                                                              error: &error];

//----- DO ERROR CHECKING (left out to simplify)

BOOL result = [xmlData writeToFile:arrayFileName atomically:YES];

Boom. An XML file.

I'm backing up a core data file and it is relatively trivial to do.

I normally like Ray Wenderlich's web site, but in this case he makes something that is very easy to do very complex. I've done it that way and honestly, the Apple way is much, much easier.

Upvotes: 1

Matt Hudson
Matt Hudson

Reputation: 7358

There is a very good tutorial by Ray Wenderlich's web site (a great iOS dev and tutorial resource) on how to create XML with GDataXML here:

http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml

Here is the GitHub repo: https://github.com/neonichu/GDataXML

Upvotes: 3

Related Questions