views:

53

answers:

4

Hi all again! I want to create a game, that will use a level system. So i want to store my levels and to be able to change them during the game (to save the state). So i decided to use XML for storing levels. I found NSXmlParser class for reading from XML, but i can't find a writer to save the level state. In my game the level state and the level are very similar ( i have a lot of movable objects), so i don't wan't to store the level state data separated from the level it belongs. The problem is that i can't find a way to easily modify XML files on iPhone. Maybe i'm using a bad approach.

+1  A: 

You can use the C libary libxml2 to read and write XML. Here's a quick intro: Cocoa Samurai: Getting Some XML Love with libXML2.

However, have you considered using CoreData or implementing the NSCoding protocol? NSCoding would be easier to add to existing classes.

Benedict Cohen
A: 

If you throw the data in an NSDictionary, you could do (with caveats):

[myDictionary writeToFile:pathToPlist atomically:YES];
Dave DeLong
this is with no xml usage, yes ?
Andrew
@Andrew the resulting file will be XML (specifically, in Plist format)
Dave DeLong
A: 

I was in the same situation as you and decided to write my own plain old XML serializer, check out

http://code.google.com/p/xswi/

Any feedback is welcome.

Cheers

Thomas
A: 

I would recommend using KissXML. The author started in a similar situation as you and created an NSXML compatible API wrapper around libxml. He discusses the options and decisions here on his blog.

codelark
Also, this is possibly a duplicate of: http://stackoverflow.com/questions/3849270/iphone-how-to-write-xml-files/3973554#3973554
codelark