1

我已经设置了一些代码来读取来自 YouTube 的订阅的 OPML 文件。代码来自这里的 Informa RSS

当我运行代码时,我得到class missing error。我能找到的唯一引用表明 javaDOM 版本可能是错误的,因为它已更新到 DOM2.0 但未能告诉我如何修复,它只是说使用旧版本并提供了指向 javaDOM 版本 0.7 的链接?

现在,当我将 JavaDOM 0.7 安装到 Netbeans 库中时,错误消失了,直到我尝试运行或编译它并且它失败了......

现在我不知道该去哪里。

我已经为此苦苦挣扎了几天,我的主要问题是 OPML 文件具有所有相同的标签信息,即

<opml version="1.1">
<body>
    <outline text="YouTube Subscriptions" title="YouTube Subscriptions">
            <outline text="PersonOne" title="PersonOne" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCuNfoe7ozooi0LZgp6JJS4A" />
            <outline text="PersonTwo" title="PersonTwo" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCVErFSr-jdTa_QE4PPSkVJw" />
            <outline text="Person Three" title="Person Three" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCittVr8imKanO_5KohzDbpg" />
        </outline>
    </body>
</opml>

..关于如何在Java中处理这种标签组合的信息不足,我已经搜索了三天......

4

1 回答 1

0

我无法让Informa 0.7.0-alpha2读取从 YouTube 导出为 OPML 文件的订阅。OPML 由一个outline元素组成,该元素包含outline每个 RSS 订阅的多个子元素。

Informa 的OPMLParser类只查看outline元素内部的body元素,这是大多数 OPML 订阅列表的结构。它没有outline在里面寻找子元素outline

作为替代解决方案,我使用了 Java XML 解析库XOM 1.12.10。这是读取 YouTube 生成的 OPML 文件的代码:

try {
    // create an XML builder
    Builder bob = new Builder();
    // build an XML document from the OPML file
    Document doc = bob.build(new File("subscription_manager.xml"));
    // get the root element
    Element opml = doc.getRootElement();
    // get root's body element
    Element body = opml.getFirstChildElement("body");
    // get body's outline element
    Element outline = body.getFirstChildElement("outline");
    // get outline's child outline elements
    Elements outlines = outline.getChildElements("outline");
    // loop through those elements
    for (int i = 0; i < outlines.size(); i++) {
        // display each RSS feed's URL
        System.out.println(outlines.get(i).getAttributeValue("xmlUrl"));
    }            
} catch (ParsingException | IOException ex) {
    System.out.println(ex.getMessage());
}

此代码具有以下导入:

import java.io.File;
import java.io.IOException;
import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Elements;
import nu.xom.ParsingException;
于 2018-01-11T20:56:38.893 回答