|
Project Information
Featured
|
WonderXML is an extension of GData XML Node class (Gdata Objective C library) which is able to Parse xml string to objects dynamicly, and convert objects back to xml string. How to set up- iPhone applications need these build settings in the project or target:
Header Search Paths: /usr/include/libxml2
Other Linker Flags: -lxml2
- Drag all files in wonderxml group into your project.
- See a simple test in the app delegate (output is in console).
How to use it- The User Class header file
#import <Foundation/Foundation.h>
@interface User : NSObject {
NSString *billingEmailAddress;
NSString *billingSchedule;
NSString *brandID;
Boolean changePassword;
NSString *expiration;
NSString *lastAddress;
NSString *lastLogIn;
NSString *password;
NSString *preferences;
NSNumber *profileID;
NSString *settings;
NSNumber *userID;
NSString *username;
}
@property (nonatomic, assign) Boolean changePassword;
@property (nonatomic, copy) NSString *expiration;
@property (nonatomic, copy) NSString *lastAddress;
@property (nonatomic, copy) NSString *lastLogIn;
@property (nonatomic, copy) NSString *password;
@property (nonatomic, copy) NSString *preferences;
@property (nonatomic, copy) NSNumber *profileID;
@property (nonatomic, copy) NSString *settings;
@property (nonatomic, retain) NSNumber *userID;
@property (nonatomic, copy) NSString *username;
@property (nonatomic, copy) NSString *billingSchedule;
@property (nonatomic, copy) NSString *brandID;
@property (nonatomic, copy) NSString *billingEmailAddress;
@end#import "User.h"
@implementation User
@synthesize changePassword;
@synthesize expiration;
@synthesize lastAddress;
@synthesize lastLogIn;
@synthesize password;
@synthesize preferences;
@synthesize profileID;
@synthesize settings;
@synthesize userID;
@synthesize username;
@synthesize billingSchedule;
@synthesize brandID;
@synthesize billingEmailAddress;
- (void)dealloc
{
[billingEmailAddress release];
billingEmailAddress = nil;
[billingSchedule release];
billingSchedule = nil;
[brandID release];
brandID = nil;
[expiration release];
expiration = nil;
[lastAddress release];
lastAddress = nil;
[lastLogIn release];
lastLogIn = nil;
[password release];
password = nil;
[preferences release];
preferences = nil;
[settings release];
settings = nil;
[username release];
username = nil;
[userID release];
[profileID release];
[super dealloc];
}
@endNSString *testUserString = @"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<User xmlns:=\"http://bluepinme.com\"><billingSchedule>00 00 08 * * *</billingSchedule>
<brandID>9908315</brandID><changePassword>false</changePassword>
<expiration>1970-01-01T00:00:00Z</expiration><lastLogIn>1970-01-01T00:00:00Z</lastLogIn>
<password>bbbb</password><profileID>1968515</profileID><userID>1831917</userID>
<username>fffffff</username></User>"; - Sending XmlParser fromXml message
XmlParser *parser = [[[XmlParser alloc] init] autorelease];
User *user = [[[User alloc] init] autorelease];
NSMutableArray *userArray = [parser fromXml:testUserString withObject:user];
NSLog(@"userArray :: %@", userArray); - "userArray" will only contain a user object since we only passed in a single user node
- Convert user object to its xml string representation by sending XmlParser toXml message
user = [userArray objectAtIndex:0];
//object to xml string
NSNumberFormatter * numberFomatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFomatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * aNumber = [numberFomatter numberFromString:@"123456"];
user.userID = aNumber;
user.username = @"test";
NSString *userString = [parser toXml:user andTag:@"User" inNameSpace:@"http://bluepinme.com"];
NSLog(@"userString :: %@", userString);
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<User xmlns="http://bluepinme.com"><username>test</username><brandID>9908315</brandID><billingSchedule>00 00 08 * * *</billingSchedule>
<userID>123456</userID><lastLogIn>1970-01-01T00:00:00Z</lastLogIn><changePassword>0</changePassword><password>bbbb</password><expiration>1970-01-01T00:00:00Z</expiration>
<profileID>1968515</profileID></User>
|