开发者

NSXMLParser - Parse an XML-file but it shows me the results twice

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开发者_JAVA百科:(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];
   }
}

but it shows:

test1234567test

test1234567test


This post on Big Nerd Ranch taught me a lot about using NSXMLParser to parse XML.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜