我的 XML 格式是这样的:
<Rows>
<Row>
<style>String</style?
<thumbnail>String</thumbnail>
</Row>
<Row>
<style>String</style?
<thumbnail>String</thumbnail>
</Row>
</Rows>
我如何创建这样的 NSMutableArray ({style = "value"; thumbnail = "value";}.....)
这是我的代码:
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"style"]) {
element = [NSString stringWithString:elementName];
if (!soapResults) {
soapResults = [[NSMutableString alloc] init];
}
elementFound = YES;
}
if ([elementName isEqualToString:@"thumbnail1"]) {
element = [NSString stringWithString:elementName];
if (!soapResults) {
soapResults = [[NSMutableString alloc] init];
}
elementFound = YES;
}
}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
if (elementFound) {
[soapResults appendString:string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString*)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"style"]) {
[rowDict setValue:soapResults forKey:@"style"];
elementFound = NO;
soapResults = nil;
}
if ([elementName isEqualToString:@"thumbnail1"]) {
[rowDict setValue:soapResults forKey:@"thumbnail1"];
elementFound = NO;
soapResults = nil;
}
}
如果我这样做,我的格式有误,请帮帮我
提前致谢。