使用rome生成rss格式的xml.docx

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
使用rome生成rss格式的xml

项目文档里推荐使用rome或rsslib4j来生成rss格式的xml。rome是下的一个开源的项目,是一个“解析、创建、发布RSS和ATOM格式”的工具集,支持RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, and Atom 1.0 等众多版本,对rss和atom中的各个模块都进行了很好的封装,“很好很强大”。rsslib4j是gnu下的一个开源项目,“Rsslib4j is a set of Java API to parse and retrive information from a RSS Feed. It supports RSS version 0.9x ,1.0 and 2.0 specification with Doublin Core and Syndication namespace”,懒得翻译了,从名字就可以看出来,它只局限于rss相关的功能,相当于是被“阉割”了的rome吧。分别下载了两个项目的文件,看了看文档和API,里面的类基本上都差不多,也不知道用哪个好些。考虑到rome比较大而全,因此考虑使用rome来构建项目的rss生成服务。使用rome需要把rome-0.9.jar加入classpath,除此之外并没有其他的依赖。一般的,创建一个rss格式的xml文档需要用到如下包:com.sun.syndication.feed.rss 顾名思义,这个包里是封装了rss各个部分的对象,如channel,item等等com.sun.syndication.feed.rssClasses Category Channel Cloud Content Description Enclosure Guid Image Item Source TextInput com.sun.syndication.io 这个包里的类负责解析,输出等io操作com.sun.syndication.ioInterfaces DelegatingModuleGeneratorDelegatingModuleParserModuleGeneratorModuleParserWireFeedGeneratorWireFeedParserClasses SAXBuilderSyndFeedInputSyndFeedOutputWireFeedInputWireFeedOutputXmlReaderExceptions FeedExceptionParsingFeedExceptionXmlReaderException下面是一个我学习rome过程中写的一个小例子:package djn.test.rss.rome;import com.sun.syndication.feed.rss.*;import com.sun.syndication.io.FeedException;import com.sun.syndication.io.WireFeedOutput;import java.util.*;public class RssFeedFactory { public static void main(String [] args){ //新建Channel对象,对应rss中的channel/channel /* Channel对象有两个构造器,一个默认的无参构造器用于clone对象, * 平时创建Channel对象时只能使用有参构造器Channel(String type) * 这个参数type很讲究,起初我随便填写了一些字符串,都抛出异常,非法的type * 后来逼急了,上网把rome源码搞下来,才搞明白type得是rss_x.x这样的 * rome的文档里也没有写明,浪费了不少时间研究这个type究竟应该是什么。 */ Channel channel = new Channel(rss_2.0); channel.setTitle(Test RSS channels title); channel.setDescription(channel的描述); channel.setLink(/openj/rss); channel.setEncoding(GBK); //这个list对应rss中的item列表 List items = new ArrayList();

文档评论(0)

asd522513656 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档