RSS is a standard XML file. The RSS reader can read this XML file to obtain information about the article, so that users can read the blog through the RSS reader instead of the browser, we only need to dynamically generate this XML file. Rsslibj is a small and practical Java library dedicated to reading and generating RSS. The size of rsslibj is only 25 kb. Rsslibj-1_0RC2.jar? Group_id = 71153 & use_mirror = nchc & filename = rsslibj-1_0RC2.jar & 27763931 exml. jar: http://rsslibj.cvs.sourceforge.net/rsslibj/rsslibj/lib/EXML.jar? After downloading view = log, change the expanded name. Zip to. jar.
import com.rsslibj.elements.Channel;public class Writer { public static void main(String[] args) throws InstantiationException, ClassNotFoundException, IllegalAccessException { Channel channel=new Channel(); channel.setDescription("This is my sample channel."); channel.setLink("http://localhost/"); channel.setTitle("My Channel"); channel.setImage("http://localhost/", "The Channel Image", "http://localhost/foo.jpg"); channel.setTextInput("http://localhost/search", "Search The Channel Image", "The Channel Image", "s"); channel.addItem("http://localhost/item1", "The First Item covers details on the first item>", "The First Item") .setDcContributor("Joseph B. Ottinger"); channel.addItem("http://localhost/item2", "The Second Item covers details on the second item", "The Second Item") .setDcCreator("Jason Bell"); System.out.println("The feed in RDF: "+channel.getFeed("rss")); }}
Channel channel = new channel (); channel. setdescription (account. getdescription (); baseurl = baseurl. substring (0, n); channel. setlink ("http: // server-name/home. c? Accountid = "+ accountid); channel. settitle (account. gettitle (); list Articles = facade. getarticles (accountid, account. getmaxperpage (), 1); iterator it = articles. iterator (); While (it. hasnext () {Article article = (Article) it. next (); channel. additem ("http: // server-name/article. c? ArticleID = "+ article. getarticleid (), article. getsummary (), article. gettitle ();} // output XML: response. setcontenttype ("text/XML"); printwriter PW = response. getwriter (); PW. print (channel. getfeed ("RSS"); PW. close ();
This article from the "sorrow of frost" blog, source http://maomao.blog.51cto.com/115985/22180