Hey All!
I am trying to use wonderxml (http://code.google.com/p/wonderxml/) to convert my xml into objective-c objects.
It works for a simple case like below…
XML:
<Defn>
<name>Test1</name>
<add>my address</add>
</Defn>
Corresponding Class interface:
#import <Foundation/Foundation.h>
@interface Defn: NSObject {
NSString *name;
NSString *add;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *add;
@end
However if i have a XML structure like below, what should i do?
<Defn>
<contact>
<name>Test1</name>
<add>my address</add>
</contact>
<contact>
<name>Test1</name>
<add>my address</add>
</contact>
.
.
</Defn>
What should be my class interface?
In your first example the XML file goes from has the key Defn holding to strings and you ObjC example follows this pattern with an object called Defn, which contains 2 strings.
For your second example, where you have contact holding the strings and then multiple contact’s in Defn, you will probably want to use a similar pattern. Except with your Defn class being renamed to contacts and then the new Defn class holding an array of the contact objects.
So my implementation would be.
contact.h
Defn.h
This might not be the best solution but it follows the XML structure quite well and is a logical step from your original Class interface example.