有没有办法找出给定的URL是RSS提要还是使用Java的ATOM? [英] Is there any way to find if the given URLs is an RSS feed or atom using Java?

查看:45
本文介绍了有没有办法找出给定的URL是RSS提要还是使用Java的ATOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个RSS解析器。有没有办法使用Java找出给定的URL是RSS还是ATOM?

RSS

您可以使用ROME(我建议使用第一个)来解析推荐答案和Atom提要。或者,您必须使用SAX解析器或创建DOM树并执行以下操作:

对于RSS:
在RSS中,您必须检查是否有rss元素,并且其子元素必须包含channel元素。RSS中可以有0个或更多item(我可能是错的)。

示例:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
    <title>RSS Title</title>
    <description>This is an example of an RSS feed</description>
    <link>http://www.someexamplerssdomain.com/main.html</link>
    <lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
    <pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>

    <item>
        <title>Example entry</title>
        <description>Here is some text containing an interesting description of the thing to be described.</description>
        <link>http://www.wikipedia.org/</link>
        <guid>unique string per item</guid>
        <pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
    </item>

</channel>
</rss>

对于Atom:
在Atom中,您必须检查是否有feed元素。Atom中可以有0个或更多entry。(我可能错了)。

示例:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

    <title>Example Feed</title>
    <subtitle>A subtitle.</subtitle>
    <link href="http://example.org/feed/" rel="self" />
    <link href="http://example.org/" />
    <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
    <updated>2003-12-13T18:30:02Z</updated>
    <author>
        <name>John Doe</name>
        <email>johndoe@example.com</email>
    </author>

    <entry>
        <title>Atom-Powered Robots Run Amok</title>
        <link href="http://example.org/2003/12/13/atom03" />
        <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
        <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
        <updated>2003-12-13T18:30:02Z</updated>
        <summary>Some text.</summary>
    </entry>

</feed>

PS:我不知道您要实现哪个RSS版本或Atom版本,但请遵循它们的指导原则。

这篇关于有没有办法找出给定的URL是RSS提要还是使用Java的ATOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆