我是iphone开发新手,对解析不太了解。但是我尝试了以下代码来获取距离元素文本。我正在做以下链接的 XML 解析:
请检查我尝试过的代码:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:
(NSDictionary *)attributeDict
{
currentElement = [elementName copy];
if([currentElement isEqualToString:@"distance"])
{
NSLog(@"ENTER IN distance");
text = [[NSMutableString alloc]init];
{
dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:text,@"text",nil];
}
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:@"text"])
{
[dictionary setObject:text forKey:currentElement];
[text appendString:string];
NSLog(@"text....%@",text);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:
(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"distance"])
{
[distanparsingarray addObject:dictionary];
}
}
By using above method I am getting the text both of distance and duration. But I want only distance text. Please tell me what I am doing wrong in above code.
提前致谢。