I’m trying to parse a XML-file to a NSMutableArray and show it to the tableview. The problem is when it parse, it add 2 times the results of the parsing in the NSMutableArray. This lead to the tableview showing the result twice. (2 rows in the tableview)
My question is : how can i show one result instead of the twice the same result?
XML-file:
<something>test1234567test</something>
The code:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{ if([currentElement isEqualToString:@"something"])
[currentname appendString:string];
[mutarray_xml addObject:currentname];
}
i tried :
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([currentElement isEqualToString:@"something"])
{
[currentname release];
}
}
To do parsing like this correctly, you also need to implement the
didStartElementmethod. You should not be adding anything to your mutable array inside thefoundCharactersmethod – you should only add something to the array in thedidEndElementmethod, because this method indicates that the entire contents of the element has been read.