xml解析器无法读取xml的所有节点

时间:2010-04-08 13:26:40

标签: iphone nsxmlparser

您好我正在尝试从Web服务返回的xml的所有节点中获取值。但是调试器只能在didStartElement api上运行,它也应该转到其他api但只在那一点终止,它不会进一步读取它。代码:

-(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;
    }

1 个答案:

答案 0 :(得分:0)

发现我的错误,是一个愚蠢的,我没有正确处理调试