用Java编写RSS阅读器

时间:2021-12-02 01:09:00

I'm trying to write a basic RSS reader for a class project. Our book shows an example by walking the DOM tree. Is that a decent approach for an RSS reader? Would I just ignore certain tags that are of uninterest to me and not to be used by the RSS Reader? Thanks.

我正在为一个类项目编写一个基本的RSS阅读器。我们的书以遍历DOM树为例。对于RSS阅读器来说,这是一个合适的方法吗?我是否会忽略某些我不感兴趣、RSS阅读器不会使用的标签?谢谢。

5 个解决方案

#1


3  

It's one of two common approaches, so yes. And yes, ignoring tags that are not of interest is a good way to handle it. If you don't need it, no need to take note of it. If you know in advance exactly what tags you need, you probably don't need to walk the entire DOM tree.

这是两种常见的方法之一。是的,忽略不感兴趣的标记是一种很好的处理方法。如果你不需要它,就不需要注意它。如果您预先知道需要什么标记,那么您可能不需要遍历整个DOM树。

You could also use a SAX parser which would probably be faster and less memory intensive, though probably not necessary in this case, depending on how many results you wish to have in the feed.

您还可以使用SAX解析器,该解析器可能速度更快,内存占用更少,但在本例中可能不需要,这取决于您希望在提要中有多少结果。

#2


6  

For inspiration you can look at ROME, an open source tool for handling RSS & Atom feeds.

为了获得灵感,您可以查看ROME,这是一个处理RSS和Atom提要的开源工具。

#3


3  

Well, the beauty of RSS feed is they always come in some standard structure, even though some feeds contain non-standard fields, like Google Picasa's RSS feed. The most straightforward approach, in my opinion, is to use a tool that allows you to unmarshall the RSS XML feed into your RSS bean. This way, you don't need to write too much code, and you can pick what fields you want and ignore fields you don't want.

RSS提要的美妙之处在于它们总是以某种标准结构出现,尽管有些提要包含非标准字段,比如谷歌Picasa的RSS提要。在我看来,最直接的方法是使用一个工具,该工具允许您将RSS XML提要解压缩到RSS bean中。这样,您就不需要编写太多的代码,您可以选择需要的字段,并忽略不需要的字段。

In my case, I use Castor to perform the unmarshalling process where I read the Google Picasa RSS feed and gather only the fields I want. Hope this helps.

在我的例子中,我使用Castor执行反编组过程,在这个过程中我读取谷歌Picasa RSS提要并只收集我想要的字段。希望这个有帮助。

#4


2  

Processing Atom Feeds with JAXB

使用JAXB处理Atom提要

You could also map your XML to objects using JAXB. You could then use these objects in your RSS reader.

还可以使用JAXB将XML映射到对象。然后可以在RSS阅读器中使用这些对象。

The JAXB reference implementation is included in Java SE 6, there are also other implementations such as MOXy (I'm the tech lead):

JAXB参考实现包含在Java SE 6中,还有其他实现,比如MOXy(我是技术领先):

You only need to map the portions you are interested in.

您只需要映射您感兴趣的部分。

Processing Atom Feeds with SDO

使用SDO处理Atom提要

You could also use Service Data Objects (SDO) to do this:

您还可以使用服务数据对象(SDO)来实现这一点:

#5


1  

I have both parsed and produced RSS with the JDOM library. Its been around a long time and is updated in-frequently, but my experience is that it hasn't needed updating. You may want to look into it but since its quite powerful, you may find that it offers too much functionality. http://jdom.org/

我已经使用JDOM库解析和生成了RSS。它已经存在了很长一段时间,并且经常更新,但是我的经验是它不需要更新。您可能想要研究它,但由于它非常强大,您可能会发现它提供了太多的功能。http://jdom.org/

#1


3  

It's one of two common approaches, so yes. And yes, ignoring tags that are not of interest is a good way to handle it. If you don't need it, no need to take note of it. If you know in advance exactly what tags you need, you probably don't need to walk the entire DOM tree.

这是两种常见的方法之一。是的,忽略不感兴趣的标记是一种很好的处理方法。如果你不需要它,就不需要注意它。如果您预先知道需要什么标记,那么您可能不需要遍历整个DOM树。

You could also use a SAX parser which would probably be faster and less memory intensive, though probably not necessary in this case, depending on how many results you wish to have in the feed.

您还可以使用SAX解析器,该解析器可能速度更快,内存占用更少,但在本例中可能不需要,这取决于您希望在提要中有多少结果。

#2


6  

For inspiration you can look at ROME, an open source tool for handling RSS & Atom feeds.

为了获得灵感,您可以查看ROME,这是一个处理RSS和Atom提要的开源工具。

#3


3  

Well, the beauty of RSS feed is they always come in some standard structure, even though some feeds contain non-standard fields, like Google Picasa's RSS feed. The most straightforward approach, in my opinion, is to use a tool that allows you to unmarshall the RSS XML feed into your RSS bean. This way, you don't need to write too much code, and you can pick what fields you want and ignore fields you don't want.

RSS提要的美妙之处在于它们总是以某种标准结构出现,尽管有些提要包含非标准字段,比如谷歌Picasa的RSS提要。在我看来,最直接的方法是使用一个工具,该工具允许您将RSS XML提要解压缩到RSS bean中。这样,您就不需要编写太多的代码,您可以选择需要的字段,并忽略不需要的字段。

In my case, I use Castor to perform the unmarshalling process where I read the Google Picasa RSS feed and gather only the fields I want. Hope this helps.

在我的例子中,我使用Castor执行反编组过程,在这个过程中我读取谷歌Picasa RSS提要并只收集我想要的字段。希望这个有帮助。

#4


2  

Processing Atom Feeds with JAXB

使用JAXB处理Atom提要

You could also map your XML to objects using JAXB. You could then use these objects in your RSS reader.

还可以使用JAXB将XML映射到对象。然后可以在RSS阅读器中使用这些对象。

The JAXB reference implementation is included in Java SE 6, there are also other implementations such as MOXy (I'm the tech lead):

JAXB参考实现包含在Java SE 6中,还有其他实现,比如MOXy(我是技术领先):

You only need to map the portions you are interested in.

您只需要映射您感兴趣的部分。

Processing Atom Feeds with SDO

使用SDO处理Atom提要

You could also use Service Data Objects (SDO) to do this:

您还可以使用服务数据对象(SDO)来实现这一点:

#5


1  

I have both parsed and produced RSS with the JDOM library. Its been around a long time and is updated in-frequently, but my experience is that it hasn't needed updating. You may want to look into it but since its quite powerful, you may find that it offers too much functionality. http://jdom.org/

我已经使用JDOM库解析和生成了RSS。它已经存在了很长一段时间,并且经常更新,但是我的经验是它不需要更新。您可能想要研究它,但由于它非常强大,您可能会发现它提供了太多的功能。http://jdom.org/