Alex Rivera | Logout

Xml serialization library for iPhone Apps

Asked 2009-06-03T12:40:39.873
11

Apple provides the NSArchiver and NSUnachriver for object serialization / deserialization, but this can not handle any custom xml schema. So filling an object structure with the data of any custom xml schema has to be made manually. Since the iPhone developer community is rapidly growing, a lot of newbie programmer are despairing to deal with the available xml parsing possibilities.

The iPhone SDK only provides NSXmlParser for xml parsing, which is more useful to read certain parts of an xml file, than filling a whole object structure, which really is a pain.

The other possibility is the famous libxml library, which is written in ANSI C - not easy to use for someone who starts programming with objective-c and never learned proper C before. Event there are a lot of wrappers available, dealing with xml can be a pain for newbies.

And here my idea takes place. An XmlSerializer library which fills an object structure automatically could makes it a lot easier and increase the app quality for many programmers. My Idea should work like this:

The xml file

<Test name="Michael" uid="28">
    <Adress street="AlphaBetaGammastrasse 1" city="Zürich" postCode="8000" />

  <Hobbies>
    <Hobby describtion="blabla"/>
    <Hobby describtion="blupblup"/>
  </Hobbies>
</Test>

The classes to fill

@interface Test : NSObject {
    NSString *name;
    Adress *adress;
    NSArray *hobbies;
    int uid;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, retain) Adress *adress;
@property (nonatomic, retain) NSArray *hobbies;
@property (nonatomic, readwrite) int uid;
@end

@interface Adress : NSObject {
    NSString *street;
    NSString *city;
    int postCode;
}
@property (nonatomic, copy) NSString *street;
@property (nonatomic, copy) NSString *city;
@property (nonatomic, readwrite) int postCode;
@end
<
Edit
Report

2 Answers

1

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

answered 2009-11-18T19:19:45.060
0

What you are describing is buried inside of the ObjectiveResource implementations, and it supports both JSON and XML. It should be pretty easy to fork that and slim it down to just the parsing by throwing out all the connection management.

answered 2009-09-08T15:46:55.680

Your Answer