iOS XML writer class

后端 未结 4 1284
悲&欢浪女
悲&欢浪女 2021-01-12 08:38

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 XM

相关标签:
4条回答
  • 2021-01-12 09:13

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

    [myDictionary writeToFile:pathToPlist atomically:YES];
    
    0 讨论(0)
  • 2021-01-12 09:13

    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.

    0 讨论(0)
  • 2021-01-12 09:27

    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.

    0 讨论(0)
  • 2021-01-12 09:32

    Try the open source XML stream writer for iOS:

    • Written in Objective-C, a single .h. and .m file
    • One @protocol for namespace support and one for without

    Example:

    // allocate serializer
    XMLWriter* xmlWriter = [[XMLWriter alloc]init];
    
    // start writing XML elements
    [xmlWriter writeStartElement:@"Root"];
    [xmlWriter writeCharacters:@"Text content for root element"];
    [xmlWriter writeEndElement];
    
    // get the resulting XML string
    NSString* xml = [xmlWriter toString];
    

    This produces the following XML string:

    <Root>Text content for root element</Root>
    
    0 讨论(0)
提交回复
热议问题