我有一些xml,我有get属性值,我需要比较表id来获取属性值。 Dis是我的
XML
<response>
<baccarat>
<Game Gametype="Euro Baccarat 1" tableid="bc7ire5oi4uhetfd" studio="Manila-VIP">
<table type="low" min="1" max="100" >
<betType type="side" min="1" max="100" />
<betType type="tie" min="10" max="30" />
<betType type="pair" min="10" max="22" />
<betType type="chip" chip="1,5,10,25,50,75,100" />
<betType type="default" chip="0" />
</table>
<table type="regular" min="10" max="250" >
<betType type="side" min="10" max="250" />
<betType type="tie" min="10" max="30" />
<betType type="pair" min="10" max="22" />
<betType type="chip" chip="1,5,10,25,50,100,250" />
<betType type="default" chip="2" />
</table>
<table type="high" min="50" max="500" >
<betType type="side" min="50" max="500" />
<betType type="tie" min="50" max="120" />
<betType type="pair" min="50" max="90" />
<betType type="chip" chip="1,5,10,25,50,100,500" />
<betType type="default" chip="4" />
</table>
<table type="vip" min="5" max="300" >
<betType type="side" min="5" max="300" />
<betType type="tie" min="5" max="100" />
<betType type="pair" min="5" max="75" />
<betType type="chip" chip="1,5,10,25,50,100,300" />
<betType type="default" chip="1" />
</table>
<table type="agent1" min="100" max="1000" >
<betType type="side" min="100" max="1000" />
<betType type="tie" min="100" max="600" />
<betType type="pair" min="100" max="450" />
<betType type="chip" chip="10,50,100,500" />
<betType type="default" chip="1" />
</table>
<table type="agent2" min="500" max="5000" >
<betType type="side" min="500" max="5000" />
<betType type="tie" min="500" max="1200" />
<betType type="pair" min="500" max="900" />
<betType type="chip" chip="10,50,100,500" />
<betType type="default" chip="1" />
</table>
<table type="private" min="5" max="300" >
<betType type="side" min="5" max="300" />
<betType type="tie" min="5" max="100" />
<betType type="pair" min="5" max="75" />
<betType type="chip" chip="1,5,10,25,50,100,300" />
<betType type="default" chip="1" />
</table>
</Game>
<table type="low" min="1" max="100" >
<betType type="side" min="1" max="100" />
<betType type="tie" min="10" max="30" />
<betType type="pair" min="10" max="22" />
<betType type="chip" chip="1,5,10,25,50,75,100" />
<betType type="default" chip="0" />
</table>
<table type="regular" min="10" max="250" >
<betType type="side" min="10" max="250" />
<betType type="tie" min="10" max="30" />
<betType type="pair" min="10" max="22" />
<betType type="chip" chip="1,5,10,25,50,100,250" />
<betType type="default" chip="2" />
</table>
<table type="high" min="50" max="500" >
<betType type="side" min="50" max="500" />
<betType type="tie" min="50" max="120" />
<betType type="pair" min="50" max="90" />
<betType type="chip" chip="1,5,10,25,50,100,500" />
<betType type="default" chip="4" />
</table>
<table type="vip" min="5" max="300" >
<betType type="side" min="5" max="300" />
<betType type="tie" min="5" max="100" />
<betType type="pair" min="5" max="75" />
<betType type="chip" chip="1,5,10,25,50,100,300" />
<betType type="default" chip="1" />
</table>
<table type="agent1" min="100" max="1000" >
<betType type="side" min="100" max="1000" />
<betType type="tie" min="100" max="600" />
<betType type="pair" min="100" max="450" />
<betType type="chip" chip="10,50,100,500" />
<betType type="default" chip="1" />
</table>
<table type="agent2" min="500" max="5000" >
<betType type="side" min="500" max="5000" />
<betType type="tie" min="500" max="1200" />
<betType type="pair" min="500" max="900" />
<betType type="chip" chip="10,50,100,500" />
<betType type="default" chip="1" />
</table>
<table type="private" min="5" max="300" >
<betType type="side" min="5" max="300" />
<betType type="tie" min="5" max="100" />
<betType type="pair" min="5" max="75" />
<betType type="chip" chip="1,5,10,25,50,100,300" />
<betType type="default" chip="1" />
</table>
在dis xml中显示我的xml我需要检查表id如果表id属性等于dis bc8kuw8luk1dgfhy我需要进入并获取所有属性的值示例类型低我需要得到min max的属性,就像我需要获得所有属性值。现在我使用log来显示所有值我需要存储并获取我想要使用的值.Dis我在解析器中的日志
NSLog(@"elementName %@",elementName);
NSLog(@"attributeDict %@",attributeDict);
答案 0 :(得分:0)
尝试这个
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict { currentelement=[elementName mutableCopy]; if( [elementName isEqualToString:@"Game"]&&[[attributeDict objectForKey:@"tableid"] isEqualToString:@"bc8kuw8luk1dgfhy"]) { isTableIdMatching = YES; } else if(isTableIdMatching && [elementName isEqualToString:@"table"]&&[[attributeDict objectForKey:@"type"] isEqualToString:@"low"]){ lowDict = attributeDict; } } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:@"table"]&& lowDict) { NSLog(@"attribut values of type low is---%@",lowDict); lowDict = nil; }else if([elementName isEqualToString:@"Game"]){ isTableIdMatching = NO; } }