Allocate NSDictonary inside while loop:
do {
TBXMLAttribute * attribute = element->firstAttribute;
while (attribute) {
NSMutableDictionary *position = [[NSMutableDictionary alloc]init];
BOOL foundElement = NO;
if ([[TBXML elementName:element] isEqualToString:@"referencecolis"]) {
[position setObject:[TBXML textForElement:element] forKey:@"cab"];
NSLog(@"cab : %@",[TBXML textForElement:element]);
foundElement = YES;
};
if ([[TBXML elementName:element] isEqualToString:@"idagencedepart"]) {
[position setObject:[TBXML textForElement:element] forKey:@"idagencedepart"];
NSLog(@"idagencedepart : %@",[TBXML textForElement:element]);
foundElement = YES;
};
if(foundElement) //avoid adding empty NSDictonaries
{
[modulectrlcle addObject:position];
}
attribute = attribute->next;
}
if (element->firstChild)
[self traverseElement:element->firstChild];
} while ((element = element->nextSibling));
Otherwise you add same NSDictonary all over again to an array and you push all elements into same dictionary and as a result you get array with a same dictionary several times.