在这里变得非常沮丧..我究竟如何解析其中有属性的xml ..我完全迷失了,
这就是我试图解析的xml看起来像..
<Rows>
<Row SKATERID="706" MANUFACTURER="A-DZG" ISFACT="F" ISSKATE="F"/>
<Row SKATERID="318" MANUFACTURER="A.R.E." ISFACT="F" ISSKATE="T"/>
//...
</Rows>
答案 0 :(得分:6)
使用NSXMLParser委托方法:
更新了我的代码。以下是解析XML的代码。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"Row"])
{
myAttrDict = [[NSDictionary alloc] initWithDictionary:attributeDict];
}
if([elementName isEqualToString:@"Rows"]
{
rowsArray = [[NSMutableArray alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"Row"])
{
[rowsArray addObject:myAttrDict];
[myAttrDict release],myAttrDict = nil;
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"Rows Array: %@",rowsArray);
}