我正在尝试在我的应用程序中设置一个UITableView
,它将显示几个不同的RSS源。基本上,一个表用于新闻,日历和音频播客。问题是并非所有Feed都具有相同的标签。有些人使用<link>
,有些则使用<guid>
。如何设置代码来处理不同类型的RSS?我有一个名为NSObject
的{{1}},它会从每个标记中获取字符串,以便稍后在设置表时重复使用,但如果我尝试从RSSEntry
获取<link>
标记,我会得到一个nil参数其中一个使用<guid>
。
-(void)viewDidLoad {
[super viewDidLoad];
[self refresh];
}
- (void)refresh {
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:@"http://ipreacher.wordpress.com/feed",@"http://www.316apps.com/Fritch/Sermons.xml",
nil];
for (NSString *feed in _feeds) {
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}
}
- (void)parseRss:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) {
NSString *blogTitle = [channel valueForChild:@"title"];
NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = [item valueForChild:@"link"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
NSString *articleContent = [item valueForChild:@"content:encoded"];
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleContent:articleContent] autorelease];
[entries addObject:entry];
}
}
}