Java 如何使用rome解析stackoverflow作业rss以填充auther和更新字段?

Java 如何使用rome解析stackoverflow作业rss以填充auther和更新字段?,java,rome,Java,Rome,我阅读rss并获取项目。这是一个示例项目: <item> <guid isPermaLink="false">205774</guid> <link>https://stackoverflow.com/jobs/205774/java-developer-creative-dock-sro?a=170Dh8tfEzVm</link> <a10:author> <a10:name&

我阅读rss并获取项目。这是一个示例项目:

<item>
    <guid isPermaLink="false">205774</guid>
    <link>https://stackoverflow.com/jobs/205774/java-developer-creative-dock-sro?a=170Dh8tfEzVm</link>
    <a10:author>
        <a10:name>Creative Dock s.r.o.</a10:name>
    </a10:author>
    <category>java</category>
    <category>spring</category>
    <category>spring-boot</category>
    <category>docker</category>
    <category>kubernetes</category>
    <title>JAVA DEVELOPER at Creative Dock s.r.o. (Praha 5, Czechia)</title>
    <description>&lt;p&gt;Are you a&amp;nbsp;&lt;strong&gt;battlehardened Java guy,&lt;/strong&gt; looking forward to&amp;nbsp;learning new technologies? Are you interested in&amp;nbsp;being in&amp;nbsp;a&amp;nbsp;place, where awesome startups are born? Startups that directly impact everyday lives? If&amp;nbsp;your answers are &amp;ldquo;yes&amp;rdquo;, read on...&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Who are we&amp;nbsp;looking for?&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;A&amp;nbsp;backend engineer for our new R&amp;amp;D team.&lt;/strong&gt; There&amp;rsquo;s plenty of&amp;nbsp;validated &amp;ldquo;smart&amp;rdquo; projects on&amp;nbsp;our table. Take ownership of&amp;nbsp;one, join the team, and build a&amp;nbsp;working solution (microservices) from scratch&amp;nbsp;-&amp;nbsp;we&amp;nbsp;know you always wanted to&amp;nbsp;do this.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;We&amp;nbsp;are currently looking at&amp;nbsp;&lt;strong&gt;Spring Boot, Docker, Kubernetes&lt;/strong&gt; for the technologies (but are &lt;strong&gt;open to&amp;nbsp;let you change our minds&lt;/strong&gt;).&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Let&amp;rsquo;s be&amp;nbsp;honest: we&amp;nbsp;don&amp;rsquo;t look for total newbies. On&amp;nbsp;the other hand, we&amp;rsquo;ll always be&amp;nbsp;there to&amp;nbsp;help you out with everything.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Have we caught&amp;nbsp;your attention? Great! Send us&amp;nbsp;a&amp;nbsp;link to&amp;nbsp;something you&amp;rsquo;re &lt;strong&gt;proud of.&lt;/strong&gt; May it&amp;nbsp;be your Website or&amp;nbsp;Github. Linkedin will also do&amp;nbsp;the trick&amp;nbsp; And we`ll get in touch!&lt;/p&gt;</description>
    <pubDate>Mon, 18 Mar 2019 10:18:53 Z</pubDate>
    <a10:updated>2019-03-18T10:18:53Z</a10:updated>
    <location xmlns="http://stackoverflow.com/jobs/">Praha 5, Czechia</location>
</item>
但它返回:

Title: JAVA DEVELOPER at Creative Dock s.r.o. (Praha 5, Czechia)
Unique Identifier: 205774
Author: null
Updated Date: null
Category: java
Category: spring
Category: spring-boot
Category: docker
Category: kubernetes
我想,应该添加namespace()来修复它,但我不知道怎么做。

我可能做得不对,但它可以(!):

publicstaticvoidmain(字符串[]args)引发异常{
URL feedUrl=新URL(“https://stackoverflow.com/jobs/feed");
SyndFeedInput=新的SyndFeedInput();
SyndFeed feed=input.build(新的XmlReader(feedUrl));
feed.getEntries()
.forEach(条目->{
System.out.println(get(“author”,entry.getForeignMarkup());
System.out.println(get(“updated”,entry.getForeignMarkup());
});
}
私有静态字符串get(字符串名称,列表foreignMarkup){
返回foreignMarkup.stream()
.filter(e->name.equals(e.getName()))
.map(元素::getValue)
.findFirst()
.orElse(空);
}
本质上:在每个
SyncEntry
上调用
getForeignMarkup()
,然后在返回的列表中查找名称与“author”、“updated”等匹配的
元素。

我可能用错误的方法执行此操作,但它可以(!):

publicstaticvoidmain(字符串[]args)引发异常{
URL feedUrl=新URL(“https://stackoverflow.com/jobs/feed");
SyndFeedInput=新的SyndFeedInput();
SyndFeed feed=input.build(新的XmlReader(feedUrl));
feed.getEntries()
.forEach(条目->{
System.out.println(get(“author”,entry.getForeignMarkup());
System.out.println(get(“updated”,entry.getForeignMarkup());
});
}
私有静态字符串get(字符串名称,列表foreignMarkup){
返回foreignMarkup.stream()
.filter(e->name.equals(e.getName()))
.map(元素::getValue)
.findFirst()
.orElse(空);
}
本质上:对每个
SyncEntry
调用
getForeignMarkup()
,然后在返回的列表中查找名称与“author”、“updated”等匹配的
元素

Title: JAVA DEVELOPER at Creative Dock s.r.o. (Praha 5, Czechia)
Unique Identifier: 205774
Author: null
Updated Date: null
Category: java
Category: spring
Category: spring-boot
Category: docker
Category: kubernetes
public static void main(String[] args) throws Exception {
    URL feedUrl = new URL("https://stackoverflow.com/jobs/feed");
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(feedUrl));

    feed.getEntries()
        .forEach(entry -> {
            System.out.println(get("author", entry.getForeignMarkup()));
            System.out.println(get("updated", entry.getForeignMarkup()));
        });

}

private static String get(String name, List<Element> foreignMarkup) {
    return foreignMarkup.stream()
                        .filter(e -> name.equals(e.getName()))
                        .map(Element::getValue)
                        .findFirst()
                        .orElse(null);
}