SimpleXmlArchiver is an open source library/helper class that I wrote to make life easier when archiving/unarchiving Objective-C object graphs. This saves a lot of time when you have a complex domain model with lots of properties that needs archiving and unarchiving. It converts Objective-C objects into an XML structure and vice versa. The main advantage of this library as opposed to other XML libraries is that it can actually instantiate a whole object graph without having to worry about how deep it actually is; it figures it out all by itself.
The main class is SimpleArchiver.m. It features two methods:
- +(NSString *)objectToXml:(id)objectToEncode;
- +(id)xmlToObject:(NSString *)xmlString targetClass:(Class)targetClass;
The first method takes any object (tree), and traverses it using the Objective-C runtime (introspection/reflection, or whatever you wish to call it), creating an XML tree in the process. The result is a nicely readable and portable XML document string.
The second method takes an XML document string and parses it into the specified target class. Again, it uses the Objective-C runtime to traverse the object, instantiate objects and fetch the corresponding elements from the XML document using XPATH.
Both methods are based on Googles excellent GDataXML, which is in turn based on libxml2.
The library can be found on GitHub, so check it out and let me know if it’s helpful or not!