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:
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.
The error I'm getting from Memory allocation is:
OnePageCRM(55776,0xa03ef720) malloc: * error for object 0x3cac070: double free * set a breakpoint in malloc_error_break to debug
Thanks in advance, Fiona