1
Я пытаюсь разобрать фид RDF. Я не могу найти документацию о том, как это сделать в объективе c. У меня есть код для синтаксического анализа RSS и Atom-фидов (см. Ниже), я пытаюсь найти что-то похожее, которое будет работать для фида RDF.Как разобрать RDF-документ в iOS
- (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);
}
}