xml parser not able to read all the nodes of the xml
- by pankaj
Hi i am trying to get values from all the nodes of a xml returned from a web service. But my code only reads first node, it does not read it further. code:
-(void)parseData{
NuanceAppDelegate *appDel = (NuanceAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *url = @"http://cmweb.bpomatrix.net/SmartPhoneService.svc/login/";
url = [[[url stringByAppendingString:UserName] stringByAppendingString:@"/"] stringByAppendingString:Password];
url = [[url stringByAppendingString:@"/"] stringByAppendingString:appDel.CPAID];
NSLog(@"log: @%",url);
NSURL *loginURL = [NSURL URLWithString:url];
NSXMLParser *home_Parser = [[NSXMLParser alloc] initWithContentsOfURL:loginURL];
[home_Parser setDelegate:self];
dict = [[NSMutableDictionary alloc] init];
[home_Parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
if([elementName isEqualToString:@"Address"])
addressFound = TRUE;
if([elementName isEqualToString:@"Name"])
nameFound = TRUE;
if([elementName isEqualToString:@"LoyaltyNum"])
loyaltyNumFound = TRUE;
if([elementName isEqualToString:@"City"])
cityFound = TRUE;
if([elementName isEqualToString:@"Province"])
proFound = TRUE;
if([elementName isEqualToString:@"Zip"])
zipFound = TRUE;
//NSLog(@"Response %@",responseFound);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(addressFound)
{
[dict setObject:string forKey:@"address"];
addressFound = FALSE;
}
else if(nameFound)
{
[dict setObject:string forKey:@"name"];
nameFound = FALSE;
}
else if(loyaltyNumFound)
{
[dict setObject:string forKey:@"loyaltyNum"];
loyaltyNumFound = FALSE;
}
else if(cityFound)
{
[dict setObject:string forKey:@"city"];
cityFound = FALSE;
}
else if(proFound)
{
[dict setObject:string forKey:@"province"];
proFound = FALSE;
}
else if(zipFound)
{
[dict setObject:string forKey:@"zip"];
zipFound = FALSE;
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"clsUserProfile"])
{
[self parsingOver];
}
}
-(void)parsingOver
{
NuanceAppDelegate *appDel = (NuanceAppDelegate *)[[UIApplication sharedApplication] delegate];
appDel.dictProfile = dict;
}