我正在使用 NSXMLParser 解析数据。我能够得到解析的数据。但是当我使用 addObject 将它添加到 NSMutableArray 时,该数组为空。我正在使用最新的 Xcode 版本。有人可以帮帮我吗。
我正在处理的数组是 IdentificationTypes1
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"Books"]) {
}
if ([elementName isEqualToString:@"Book"]) {
if ([elementName isEqualToString:@"title"]) {
self.identificationTypes1 =[[NSMutableArray alloc]init];
}
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if (!currentElementValue) {
currentElementValue =[[NSMutableString alloc]initWithString:string];
}
else {
[currentElementValue appendString:string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"Books"]) {
NSLog(@"Count is %@",[identificationTypes1 count]);
return;
}
if ([elementName isEqualToString:@"Book"]) {
}
if ([elementName isEqualToString:@"title"]) {
NSLog(@"Curre value is %@",currentElementValue);
[self.identificationTypes1 addObject:currentElementValue];
}
currentElementValue = nil;
}