-(IBAction)refresh:(id)sender{
[progress startAnimation:nil];
NSURL *url = [NSURL URLWithString:@"http://www.macmaniacos.com/blog/feed/"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
if(!urlData){
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
return;
}
if(doc)
[doc release];
doc = [[NSXMLDocument alloc] initWithData:urlData options:0 error:&error];
if(!doc){
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
return;
}
if(itemNodes)
[itemNodes release];
itemNodes = [[doc nodesForXPath:@"/rss/channel/item/title" error:&error] retain];
NSLog(@"%@", itemNodes);
if(!itemNodes){
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
return;
}
NSLog(@"%@", doc);
[tableView reloadData];
[progress stopAnimation:nil];
}
-(NSString *)stringForPath:(NSString *)xp ofNode:(NSXMLNode *)n{
NSError *error;
NSArray *nodes = [n nodesForXPath:xp error:&error];
if(!nodes){
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
return nil;
}
if([nodes count] == 0)
return nil;
else{
return [[nodes objectAtIndex:0] stringValue];
}
}
-(int)numberOfRowsInTableView:(NSTableView *)tv{
NSLog(@"%d", [itemNodes count]);
return [itemNodes count];
}
-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)column row:(int)row{
NSLog(@"%@", [self stringForPath:[column identifier] ofNode:[itemNodes objectAtIndex:row]]);
return [self stringForPath:[column identifier] ofNode:[itemNodes objectAtIndex:row]];
}