解析 RSS 提要的主体
我试图弄清楚是否可以以某种方式获取我的 WordPress RSS 提要的主体。尽管我的 WordPress 设置可以显示每篇文章的全文,但当我在 iPhone 上解析它时,我只能得到摘要。
这是我的代码示例:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
self.currentTitle = [[NSMutableString alloc] init];
self.currentSummary = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
[item setObject:self.currentTitle forKey:@"title"];
[item setObject:self.currentSummary forKey:@"summary"];
[items addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"title"]) {
[self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[self.currentSummary appendString:string];
}
}
这是根据示例拼凑而成的。我已经通过将整个事情变成一个字符串并记录它来验证主体是否存在。我仍然不知道我到底如何知道要使用什么标签或标题。例如:“项目”、“描述”、“pubDate”、“标题”。谁知道要使用什么标签?请帮忙。
I am trying to figure out if I can somehow get the main body of my Wordpress RSS feed. Even though I have my wordpress settings to show the full text of each post, when I parse it on the iPhone, I am only getting the summary.
Here is a sample of my code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
self.currentTitle = [[NSMutableString alloc] init];
self.currentSummary = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
[item setObject:self.currentTitle forKey:@"title"];
[item setObject:self.currentSummary forKey:@"summary"];
[items addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"title"]) {
[self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[self.currentSummary appendString:string];
}
}
This has been pieced together from examples. I have verified that the main body is there by making the whole thing a string and logging it. I still don't have any idea how in the world I know what tag or title to use. For example: "item", "description", "pubDate", "title". How does anyone know what tag to use? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
帖子的全文应位于每个
内的
元素中。此页面 很好地讨论了在 iOS 中解析 XML 的各种方法 - 如果您不处理大量内容,那么使用基于 DOM 的解析器可能会更容易。
The full text of the post should be in the
<content:encoded>
element within each<item>
.This page provides a good discussion of various methods of parsing XML in iOS - it might be easier to use one of DOM based parsers if you're not dealing with lots of content.