Xml serialization library for iPhone Apps [closed] Xml serialization library for iPhone Apps [closed] xml xml

Xml serialization library for iPhone Apps [closed]


The NSKeyedArchiver works precisely because it doesn't try to map onto an XML schema. Many, many XML schemas are badly designed (i.e. they're translating an in-memory object structure to an external representation format). The key problem is that the documents should be designed to make sense from a document perspective, and that that would then need to map onto whatever memory layout you wanted for your objects. Ever seen XML documents with lots of 'refid' attributes referring to other parts of the doc? Those are usually transliterated from a relational database which is just sticking angled brackets on the resultset.

So starting by assuming a one-to-one mapping between an XML document and its code representation is pretty much doomed in all but the simplest cases. Just consider where we would be today with HTML if it had been designed around the C++ objects that were used to instantiate the document in the first browser ... (well, more like Objective-C, but hey ...)

The point about NSKeyedArchiver is that you can evolve the data structure without breaking the ability to load older versions. It's unbelievably difficult to do that (properly) using some kind of automated instance-var-to-element mapping.


This is a quite good idea, implementation wise I would do it by implementing NSXMLArchiver and NSXMLUnarchiver as subclasses of NSCoder. This way any class conforming to the NSCoding protocol could easily be serialized to and from XML.

One performance hit when serializing to XML will be the primitive values as attributes, because you can not guarantee the order an object will request data to be encoded. So if attributes is what you want, then it will be quite huge in memory buffers. But it would be a fun exercise.

As for how popular it would be? Not so popular I think. The use-case just is too small.

  • Device-to-device - Simply using NSKeyedArchiver is way easier, and MUCH more compact.
  • Device-to-new server - The new server would have to implement the same scheme as well, serializing to Java, C# or whatever.
  • Device-to-existing server - The XML format is already fixed, and most probably not close to this.


I have started a similar open source project. I have named it SAMIXOS. you can visit this page and try it.Its in initial development. It works similar to what Enyra has asked.

Soon i will provide a sample code.

http://sourceforge.net/projects/samixos/

Sami