I was wondering if anybody can help me with parsing XML from RSS feeds. I am following the tutorial in iPhone in Action by Allen and Appelcline. I've got the .xml file to be read by the parser and display its table elements but when I then select a table entry the controller takes me to a new tableview for that title OLK but it does not show the contents of the feed. I've followed a trace using NSLog and it actions didSelectRowAt OK then pushes the new next table controller and it does initWithURL but then returns control to the didSelectRowAt when I think it should be processing the parser delegates.
I've listed the code below and as far as I can see it's straight from the book's code. Anybody any ideas why the elements are not displaying?
Thanks in advance.
-(id)initWithURL:(NSString *)url {
NSLog(@"initWithURL");
if (self = [super init]) {
feedList = [[NSMutableArray alloc] initWithCapacity:0];
//feedList = [[NSMutableArray alloc] init];
NSXMLParser *nextParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
[nextParser setDelegate:self];
[nextParser parse];
NSLog(@"endparse");
}
return self;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namsespaceURI:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
NSLog(@"rssviewparser");
if ([elementName compare:@"item"] == NSOrderedSame) {
currentItem = [[NSMutableDictionary alloc] initWithCapacity:0];
//currentItem = [[NSMutableDictionary alloc] init];
}
else {
if (currentItem !=NULL) {
currentContents = [[NSMutableString alloc] initWithCapacity:0];
//currentContents = [[NSMutableString alloc] init];
}
}
} -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { NSLog(@"foundchars"); if (currentContents && string) { [currentContents appendString:string]; } } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { NSLog(@"didendparser"); if ([elementName compare:@"item"] == NSOrderedSame) { [feedList addObject:currentItem]; [currentItem release]; } else if (currentItem && currentContents) { [currentItem setObject:currentContents forKey:elementName]; currentContents = nil; [currentContents release]; } }
-(void)parserDidEndDocument:(NSXMLParser *)parser {
[parser release];
} - (void)viewDidLoad { [super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}