The problem is that you do nothing to stop foundCharacters
from appending data for the other occurrences of table_data
. You could have your didStartElement
save the attributeDict[@"attr"]
value, too, and then foundCharacters
could check both elementoCorrente
as well as this new ivar in which you're holding the attributeDict[@"attr"]
value. For example:
- (void)parser:(NSXMLParser*)parser didStartElement:(NSString *)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary*)attributeDict {
elementoCorrente = nil;
atributoCorrente = nil;
if ([elementName isEqualToString:@"table_data"]) {
if ([attributeDict[@"attr"] isEqualToString:@"one"]) {
elementoCorrente = [elementName copy];
atributoCorrente = [attributeDict[@"attr"] copy];
stringDesc = [[NSMutableString alloc] init];
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([elementoCorrente isEqualToString:@"table_data"] && [atributoCorrente isEqualToString:@"one"]) {
[stringDesc appendString:string];
}
}
Frankly, you probably want a didEndElement
implementation, too, that saves stringDesc
wherever you wanted to save it, and then sets elementoCorrente
to nil
.