这是XML数据:
<Categorys> <Category> <categoryId>25</categoryId> <categoryName>My Photos</categoryName> <categoryDescription>Description</categoryDescription> <categoryIconPath>7.jpg</categoryIconPath> <userId>2</userId> <categoryStatus>ON</categoryStatus> <publicPrivate>Private</publicPrivate> </Category> ......more categories <Categorys>
在这里,我想得到< categoryName>我的NSMutableArray categList中的值.
我使用的代码是:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary*)attributeDict { if ( [elementName isEqualToString:@"categList"]) { // addresses is an NSMutableArray instance variable if (!categList) categList = [[NSMutableArray alloc] init]; return; } NSLog(@"StartedElement %@",elementName); element = [NSMutableString string]; } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(element == nil) element = [[NSMutableString alloc] init]; [element appendString:string]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { NSLog(@"Found an element named: %@ with a value of: %@",elementName,element); if ([elementName isEqualToString:@"categoryName"]) { NSLog(@"\n\n\nfound::::::::::::::: %@",element); category = element; NSLog(@"category:::: %@",category); } [categList addObject:element]; NSLog(@"categList*************** %@",categList); }
但我没有在我的NSMutableArray categList中获取类别名称:
我的代码有什么问题?