- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    currentKey = nil;
    [currentStringValue release];
    currentStringValue = nil;
    if([elementName isEqualToString:@"Value"]){
        //alloc some object to parse value into
    } else if([elementName isEqualToString:@"Signature"]){
        currentKey = @"Signature";
        return;
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    if(currentKey){
        if(!currentStringValue){
            currentStringValue = [[NSMutableString alloc] initWithCapacity:200];
        }
        [currentStringValue appendString:string];
    }
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    if([elementName isEqualToString:@"Signature"] && [currentStringValue intValue] == 804){
        ivar.signature = [currentStringValue intValue];
        return;
    }
}

Something like this. Note I havent really tested this code on compiler so there will be syntax errors here & there.


You may want to look into using TouchXML - https://github.com/mrevilme/TouchXML which offers some nice XML handling features including the use of XPATH which makes what you are trying to do much simpler.

A hypothetical example based on your model:

//first, load an XML document
CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithXMLString:someXMLString options:0 error:&error];

//get node
CXMLNode *amountNode = [xmlDoc nodeForXPath:@"//Value[@Signature='-804']/Amount" error:&error];

//or get actual value of node
NSSString *amountString =  = [[xmlDoc nodeForXPath:@"//Value[@Signature='-804']/Amount" error:&error] stringValue];

Note: None of these exapmles are tested.

I have found TouchXML very useful and compact.

Hope this helps.


There are effectively two approaches to parsing XML - an event driven one (such as that used by NSXMLParser) and a tree approach (such as that used by NSXML).

If you're only after specific elements, then it would probably be a lot easier to use the tree approach used by NSXML as it'll enable you to query XML documents using XPath (and indeed XQuery) to return specific nodes, etc. that you're interested in.

If this sounds like it might be a more fruitful approach that using NSXMLParser to iterate over the whole structure, then I'd recommend reading the Introduction to Tree-Based XML Programming Guide for Cocoa. (The "Querying an XML Document" section should be of particular interest.)