rss在web开发过程中的全方位应用

      http://www.qqvan.com/item/ri6

 

      简介:这是rss在web开发过程中的全方位应用。的详细页面,介绍了和java,.net,rss,csdn,sun,entry,有关的知识,加入收藏请按键盘ctrl+D,谢谢大家的观看!要查看更多有关信息,请点击此处

 在web当中应用,要有以下两个开发包,

  jdom.jar:jdom开源项目中(http://www.jdom.org/)

  rome.jar : rome开源项目中(http://wiki.java.net/bin/view/javawsxml/rome)

  关于rss在javaweb中的应用,分为两个步骤实施:

  1.生成rss格式的xml文件:

  

      public class feedwriter {

和 "rss在web开发过程中的全方位应用。" 有关的java编程小帖士:

strong>Locale.equals

比较当前Locale对象和作为参数传入的Locale对象。

语法

public boolean equals ( Object obj );

参数

obj

与当前Locale对象相比较的对象。

返回值

如果两个Locale对象合理地相等(logically equivalent),则返回true,否则返回false。

说明

用这个方法比较当前Locale对象和作为参数传入的Locale对象。如果两个Locale对象描述的是同一个场所,则返回true。

  private static final string date_format = "yyyy-mm-dd";

 

  public static void main(string[] args) {

  boolean ok = false;

  if (args.length==2) {

  try {

  string feedtype = args[0];

  string filename = args[1];

  dateformat dateparser = new simpledateformat(date_format);

  syndfeed feed = new syndfeedimpl(); //feed流

  feed.setfeedtype(feedtype); //设置rss版本

  feed.settitle("sample feed (created with rome)"); //< title>设置标题

  feed.setlink(http://www.csdn.net); //< link>

  feed.setdescription("this feed has been created using rome (java syndication utilities");

  list entries = new arraylist();

  syndentry entry;

  syndcontent description;

  entry = new syndentryimpl(); //子节点

  entry.settitle("rome v1.0");

  entry.setlink(http://www.csdn.net);

  entry.setpublisheddate(dateparser.parse("2004-06-08"));

  description = new syndcontentimpl();

  description.settype("text/plain");

  description.setvalue("initial release of rome");

  entry.setdescription(description);

  entries.add(entry);

  entry = new syndentryimpl();

  entry.settitle("rome v2.0");

  entry.setlink(http://ww.csdn.net);

  entry.setpublisheddate(dateparser.parse("2004-06-16"));

  description = new syndcontentimpl(); //描述

  description.settype("text/xml");

  description.setvalue("bug fixes, < xml>xml< /xml> minor api changes and some new features");

  entry.setdescription(description);

  entries.add(entry);

  entry = new syndentryimpl();

  entry.settitle("rome v3.0");

  entry.setlink("http://www.csdn.net");

  entry.setpublisheddate(dateparser.parse("2004-07-27"));

  description = new syndcontentimpl();

  description.settype("text/html");

  description.setvalue("< p>more bug fixes, mor api changes, some new features and some unit testing< /p>"+

  "< p>for details check the < a href=\"http://www.csdn.net\">changes log< /a>< /p>");

  entry.setdescription(description);

  entries.add(entry);

  feed.setentries(entries); //设置子节点

  writer writer = new filewriter(filename);

  syndfeedoutput output = new syndfeedoutput();

  output.output(feed,writer); //写到文件中去

  writer.close();

  system.out.println("the feed has been written to the file ["+filename+"]");

  ok = true;

  }

  catch (exception ex) {

  ex.printstacktrace();

  system.out.println("error: "+ex.getmessage());

  }

  }

  if (!ok) {

  system.out.println();

  system.out.println("feedwriter creates a rss/atom feed and writes it to a file.");

  system.out.println("the first parameter must be the syndication format for the feed");

  system.out.println(" (rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3)");

  system.out.println("the second parameter must be the file name for the feed");

  system.out.println();

  }

  }

  }

 2.对此xml文件的读取:

  

      < %@page contenttype="text/html"%>

  < %@page pageencoding="utf-8"%>

  < html>

  < head>

  < meta http-equiv="content-type" content="text/html; charset=utf-8">

  < title>sina news< /title>

  < /head>

  < body>

  < %

  java.util.properties systemsettings = system.getproperties();

  systemsettings.put("http.proxyhost", "mywebcache.com");

  systemsettings.put("http.proxyport", "8080");

  system.setproperties(systemsettings);

  string urlstr = "http://rss.sina.com.cn/news/marquee/ddt.xml";

  java.net.urlconnection feedurl = new java.net.url(urlstr).openconnection();

  feedurl.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 5.0; windows nt; digext)");

  com.sun.syndication.io.syndfeedinput input = new com.sun.syndication.io.syndfeedinput();

  com.sun.syndication.feed.synd.syndfeed feed = input.build(new com.sun.syndication.io.xmlreader(feedurl));

  %>

  < div align="center">

  < h1>< %=feed.gettitle()%>< /h1>

  < table border=1 cellpadding=3 width="700">

  < tr>

  < th>number< /th>

  < th>title< /th>

  < th>time< /th>

  < /tr>

  < %

  java.util.list list = feed.getentries();

  for (int i=0; i< list.size(); i++) {

  com.sun.syndication.feed.synd.syndentry entry = (com.sun.syndication.feed.synd.syndentry)list.get(i);

  %>

  < tr>

  < td>< %=i+1%>< /td>

  < td>< a href="< %=entry.getlink()%>">< %=entry.gettitle()%>< /a>< /td>

  < td>< %=entry.getpublisheddate()%>< /td>

  < /tr>

  < %}%>

  < /table>

  < /div>

  < br>

  < /body>

  < /html>

你可能感兴趣的:(编程,Web,.net,xml,sun)