解析 RSS 提要的主体

发布于 2024-11-29 09:25:17 字数 1399 浏览 0 评论 0原文

我试图弄清楚是否可以以某种方式获取我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2024-12-06 09:25:17

帖子的全文应位于每个 内的 元素中。

此页面 很好地讨论了在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文