I'm trying to parse this xml file. The problem I'm having is that I'd like to use the
-(void)parser:(NSXMLParser*)parser didStartElement
...
to drill down into several levels of this xml file.
This is what I have so far:
#pragma didStartElement (from the parser protocol)
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
// Choose the tag
if ([elementName isEqualToString:@"item"]) {
NSString *firstName = [attributeDict valueForKey:@"firstname"];
NSString *lastName = [attributeDict valueForKey:@"lastname"];
NSString *birthDay = [attributeDict valueForKey:@"birthday"];
Politician *politician = [[Politician alloc] initWithName:firstName lName:lastName bDay:birthDay];
if (politician != nil) {
[people addObject:politician];
}
}
}
The problem is that this code does not drill down. Is there a way to selectively start the parsing from a specific tag (say: person) and check for the keys of that tag or to rewrite the "elementName's" value so I can use multipe if statements? What's the right way of doing this? Thanks much.