Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-03-2010, 06:04 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 8
elephant85 is on a distinguished road
Default TouchXML - reading into an object

Hey everyone,

So I have an XML file and am using TouchXML to read it. There are only some elements in the XML file that I require.
So I created a class 'Contact' with properties that I wish to save from the XML file.
What i've come up with so far is this:

Code:
	NSMutableArray *res = [[NSMutableArray alloc] init]; 
	CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; 
	NSArray *nodes = nil; 
	
	//! searching for item nodes 
	nodes = [doc nodesForXPath:@"/statuses/status/user" error:nil]; 


	for (CXMLElement *node in nodes) 
	{ 
		int counter; 

		Contact *contact  = [[Contact alloc] init]; 
		for (counter = 0; counter < [node childCount]; counter++) 
		{ 
			//pulling out name and description only for the minute!!!
			if ([[[node childAtIndex:counter] name] isEqual:@"name"]){

				contact.name = [[node childAtIndex:counter] stringValue];
				
			}else if ([[[node childAtIndex:counter] name] isEqual:@"description"]) {
				
				// common procedure: dictionary with keys/values from XML node 
				if ([[node childAtIndex:counter] stringValue] == NULL){
					contact.nextAction = @"No description";
				}else{
					contact.nextAction = [[node childAtIndex:counter] stringValue];
				}
				
			}else if ([[[node childAtIndex:counter] name] isEqual:@"created_at"]){
				NSString *str = [[NSString alloc] init];
				str = [[node childAtIndex:counter] stringValue];
				contact.date = str;
				[str release];
			}else if([[[node childAtIndex:counter] name] isEqual:@"time_zone"]){
				
				contact.status = [[node childAtIndex:counter] stringValue];
				[res addObject:contact];
				[contact release];
			}
		} 
	}
	self.contactsArray = res;
	[res release];
	[self.tableView reloadData];
However I have some concerns... I'm not to sure about the creation of the object and its release... I think it might be causing me memory problems but I've tried a few different ways of doing this and haven't been able to find a solution.
Can somebody tell me if what i'm doing is completely wrong? or is there another/better way of doing it.

Thanks in advance,
Fiona
elephant85 is offline   Reply With Quote
Reply

Bookmarks

Tags
touchxml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 353
13 members and 340 guests
ajay123123, Anwerbl, Arty Tales, ashaman64, baja_yu, ChrisYates, HemiMG, mini998, mottdog, newDev, Objective Zero, oceanlablight, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:59 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0