views:

50

answers:

1

Dear all, I have an XML node like this : < State id="1" > AA < /State > how can i read the value 'AA' ? I'm able to read the id value "1" using


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {

    //Extract the attribute here.
    aState.stateId = [[attributeDict objectForKey:@"id"] integerValue];
    NSLog(@"Reading id value :%i", aState.stateId);
}
NSLog(@"Processing Element: %@", elementName);

}
But not able to read the value,
please help me, thanks in advance

A: 

As far as i remember, to do this you should implement this method

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

Entire code will look like this:

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {

    foundState = [elementName isEqualToString:@"State"];

    }
 - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
      if (foundState) {
        [stringBuffer appendString:string];
      }
   }
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 

namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    if (foundState) {
      NSLog(@"AA = %@", stringBuffer);
      foundState = NO;
    }
}
eviltrue