我在获取 xml 响应中的属性值时遇到问题
xml
<History>
<master ids=\"1\" >
<historypoints id=\"1\" bankerpoint=\"9\" playerpoint=\"0\" win=\"1\" playerpair=\"0\" bankerpair=\"0\" />
</master>
<master ids=\"2\" >
<historypoints id=\"2\" bankerpoint=\"5\" playerpoint=\"7\" win=\"0\" playerpair=\"0\" bankerpair=\"0\" />
<historypoints id=\"3\" bankerpoint=\"6\" playerpoint=\"7\" win=\"0\" playerpair=\"0\" bankerpair=\"0\" />
<historypoints id=\"4\" bankerpoint=\"0\" playerpoint=\"4\" win=\"0\" playerpair=\"0\" bankerpair=\"0\" />
</master>
<master ids=\"3\" >
<historypoints id=\"5\" bankerpoint=\"5\" playerpoint=\"3\" win=\"1\" playerpair=\"0\" bankerpair=\"0\" />
<historypoints id=\"6\" bankerpoint=\"6\" playerpoint=\"0\" win=\"1\" playerpair=\"0\" bankerpair=\"0\" />
<historypoints id=\"7\" bankerpoint=\"9\" playerpoint=\"0\" win=\"1\" playerpair=\"1\" bankerpair=\"0\" />
<historypoints id=\"8\" bankerpoint=\"6\" playerpoint=\"0\" win=\"1\" playerpair=\"0\" bankerpair=\"0\" />
</master>
<master ids=\"4\" >
<historypoints id=\"9\" bankerpoint=\"0\" playerpoint=\"8\" win=\"0\" playerpair=\"0\" bankerpair=\"0\" />
</master>
在上面的 xml 中,我需要在一个数组中获取“win”属性值,任何人都可以帮我解决这个问题,谢谢。
显示我的代码
NSString *label;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSLog(@"elementName %@",elementName);
NSLog(@"attributeDict %@",attributeDict);
if ([elementName isEqualToString:@"History"]) {
label = @"History";
}
else if ([elementName isEqualToString:@"historypoints"]) {
label = @"historypoints";
if ([attributeDict valueForKey:@"win"]) {
NSLog(@"Log values is more useful ");
label = @"win";
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"foundCharacters %@",string);
if ([label isEqualToString:@"win"]){
self.typeStr = string;
[typearr addObject:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSLog(@"didEndElement elementName:%@",elementName);
}