我如何用 rome 解析堆栈溢出作业 rss 以填充作者和更新的字段?
How I could parse stackoverflow jobs rss with rome to fill auther and updated fields?
我阅读了 Whosebug 作业 rss 并获取了项目。这是一个示例项目:
<item>
<guid isPermaLink="false">205774</guid>
<link>https://whosebug.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><p>Are you a&nbsp;<strong>battlehardened Java guy,</strong> looking forward to&nbsp;learning new technologies? Are you interested in&nbsp;being in&nbsp;a&nbsp;place, where awesome startups are born? Startups that directly impact everyday lives? If&nbsp;your answers are &ldquo;yes&rdquo;, read on...</p><br /><p><strong>Who are we&nbsp;looking for?</strong></p><br /><p><strong>A&nbsp;backend engineer for our new R&amp;D team.</strong> There&rsquo;s plenty of&nbsp;validated &ldquo;smart&rdquo; projects on&nbsp;our table. Take ownership of&nbsp;one, join the team, and build a&nbsp;working solution (microservices) from scratch&nbsp;-&nbsp;we&nbsp;know you always wanted to&nbsp;do this.</p><br /><p>We&nbsp;are currently looking at&nbsp;<strong>Spring Boot, Docker, Kubernetes</strong> for the technologies (but are <strong>open to&nbsp;let you change our minds</strong>).</p><br /><p>Let&rsquo;s be&nbsp;honest: we&nbsp;don&rsquo;t look for total newbies. On&nbsp;the other hand, we&rsquo;ll always be&nbsp;there to&nbsp;help you out with everything.</p><br /><p>Have we caught&nbsp;your attention? Great! Send us&nbsp;a&nbsp;link to&nbsp;something you&rsquo;re <strong>proud of.</strong> May it&nbsp;be your Website or&nbsp;Github. Linkedin will also do&nbsp;the trick&nbsp; And we`ll get in touch!</p></description>
<pubDate>Mon, 18 Mar 2019 10:18:53 Z</pubDate>
<a10:updated>2019-03-18T10:18:53Z</a10:updated>
<location xmlns="http://whosebug.com/jobs/">Praha 5, Czechia</location>
</item>
我尝试用这段代码解析它:
URL feedUrl = new URL("https://whosebug.com/jobs/feed");
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
但它返回:
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://whosebug.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);
}
本质上:在每个 SyncEntry
上调用 getForeignMarkup()
,然后在返回的列表中查找名称与 "author"、"updated" 匹配的 Element
,等...
我阅读了 Whosebug 作业 rss 并获取了项目。这是一个示例项目:
<item>
<guid isPermaLink="false">205774</guid>
<link>https://whosebug.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><p>Are you a&nbsp;<strong>battlehardened Java guy,</strong> looking forward to&nbsp;learning new technologies? Are you interested in&nbsp;being in&nbsp;a&nbsp;place, where awesome startups are born? Startups that directly impact everyday lives? If&nbsp;your answers are &ldquo;yes&rdquo;, read on...</p><br /><p><strong>Who are we&nbsp;looking for?</strong></p><br /><p><strong>A&nbsp;backend engineer for our new R&amp;D team.</strong> There&rsquo;s plenty of&nbsp;validated &ldquo;smart&rdquo; projects on&nbsp;our table. Take ownership of&nbsp;one, join the team, and build a&nbsp;working solution (microservices) from scratch&nbsp;-&nbsp;we&nbsp;know you always wanted to&nbsp;do this.</p><br /><p>We&nbsp;are currently looking at&nbsp;<strong>Spring Boot, Docker, Kubernetes</strong> for the technologies (but are <strong>open to&nbsp;let you change our minds</strong>).</p><br /><p>Let&rsquo;s be&nbsp;honest: we&nbsp;don&rsquo;t look for total newbies. On&nbsp;the other hand, we&rsquo;ll always be&nbsp;there to&nbsp;help you out with everything.</p><br /><p>Have we caught&nbsp;your attention? Great! Send us&nbsp;a&nbsp;link to&nbsp;something you&rsquo;re <strong>proud of.</strong> May it&nbsp;be your Website or&nbsp;Github. Linkedin will also do&nbsp;the trick&nbsp; And we`ll get in touch!</p></description>
<pubDate>Mon, 18 Mar 2019 10:18:53 Z</pubDate>
<a10:updated>2019-03-18T10:18:53Z</a10:updated>
<location xmlns="http://whosebug.com/jobs/">Praha 5, Czechia</location>
</item>
我尝试用这段代码解析它:
URL feedUrl = new URL("https://whosebug.com/jobs/feed");
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
但它返回:
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://whosebug.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);
}
本质上:在每个 SyncEntry
上调用 getForeignMarkup()
,然后在返回的列表中查找名称与 "author"、"updated" 匹配的 Element
,等...