我已经解析了xml文件。
控制台正确显示解析的元素,但数组显示为空。
- (ParserClass *) initXMLParser
{
//[super init];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"note"]) {
//Initialize the array.
appDelegate.testArray = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"to"]) {
aTest = [[Test alloc] init];
}
NSLog(@"Processing Element: %@", elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing Value: %@", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Books"])
return;
if([elementName isEqualToString:@"note"]) {
[appDelegate.testArray addObject:aTest];
//[aBook release];
aTest = nil;
}
else
[aTest setValue:currentElementValue forKey:elementName];
//[currentElementValue release];
currentElementValue = nil;
}
@end