'cannot get value when parsing XML in iPhone SDK

I have used following code to parse the xml file but I can't get value

 (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {
    
    if([elementName isEqualToString:@"Query"]) {
        //Initialize the array.
        appDelegate.books = [[NSMutableArray alloc] init];
    }
    else if([elementName isEqualToString:@"city"]) {
        
        //Initialize the book.
        aBook = [[Book alloc] init];
        
        //Extract the attribute here.
        aBook.bookID = [attributeDict objectForKey:@"name"];
        
        //NSLog(@"Reading id value :%i", aBook.bookID);
    }
    
    //NSLog(@"Processing Element: %@", elementName);
}
<Query type="cities" status="0" message="success"> 
<city code="AAL" name="Aalborg DK "/> 
<city code="AES" name="Aalesund NO "/> 
<city code="AAR" name="Aarhus DK "/> 
<city code="YXX" name="Abbotsford BC CA "/> 
<city code="ABZ" name="Aberdeen GB "/> 
<city code="ABR" name="Aberdeen SD US "/> 
<city code="AHB" name="Abha SA "/> 
<city code="ABJ" name="Abidjan CI "/> 
<city code="ABI" name="Abilene TX US "/> 
<city code="AUH" name="Abu Dhabi Intl Apt AE "/> 
<city code="ABS" name="Abu Simbel EG "/> 
<city code="ABV" name="Abuja Intl NG "/>


Solution 1:[1]

You need at least 3 of the NSXMLParser delegates to get XML to parse properly - check here: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/XMLParsing/Articles/UsingParser.html to see actual instructions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James