私はxml応答disで属性値を取得するのに問題があります
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 では、1 つの配列で "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);
}