Reputation: 241
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];
}
}
Upvotes: 1
Views: 246
Reputation: 75296
To do parsing like this correctly, you also need to implement the didStartElement
method. You should not be adding anything to your mutable array inside the foundCharacters
method - you should only add something to the array in the didEndElement
method, because this method indicates that the entire contents of the element has been read.
Upvotes: 0
Reputation: 113757
This post on Big Nerd Ranch taught me a lot about using NSXMLParser to parse XML.
Upvotes: 2