我正在尝试解析RDF Feed。我找不到任何关于如何在目标c中执行此操作的文档。我有解析RSS和Atom提要的代码(如下所示),我试图找到类似于RDF提要的东西。
- (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 = nil;
RSSEntry *entry = [[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleImageUrl:@"test"];
[entries addObject:entry];
}
}
}
- (void)parseAtom:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
NSString *blogTitle = [rootElement valueForChild:@"title"];
NSArray *items = [rootElement elementsForName:@"entry"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = nil;
NSArray *links = [item elementsForName:@"link"];
for(GDataXMLElement *link in links) {
NSString *rel = [[link attributeForName:@"rel"] stringValue];
NSString *type = [[link attributeForName:@"type"] stringValue];
if ([rel compare:@"alternate"] == NSOrderedSame &&
[type compare:@"text/html"] == NSOrderedSame) {
articleUrl = [[link attributeForName:@"href"] stringValue];
}
}
NSString *articleDateString = [item valueForChild:@"updated"];
NSDate *articleDate = nil;
RSSEntry *entry = [[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleImageUrl:@"test"];
[entries addObject:entry];
}
}
- (void)parseFeed:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
if ([rootElement.name compare:@"rss"] == NSOrderedSame) {
[self parseRss:rootElement entries:entries];
} else if ([rootElement.name compare:@"feed"] == NSOrderedSame) {
[self parseAtom:rootElement entries:entries];
} else {
NSLog(@"Unsupported root element: %@", rootElement.name);
}
}
答案 0 :(得分:0)
尝试使用Raptor RDF解析器库 你可以在这里找到下载链接: http://www.downloadplex.com/Mac/Development/Components-Libraries/raptor-rdf-parser-for-mac_224150.html
祝你好运:)