Implement RSS in Java

Source: Internet
Author: User

RSS is a standard XML file. The Rss reader can read this XML file to obtain information about the article.
Instead of reading the Blog through a browser, we only need to dynamically generate the XML file. RSSLibJ is a small version dedicated to reading and generating RSS
A Practical Java library with a size of only 25 k can be downloaded from [url] http://sourceforge.net/projects/rsslibj/#/url#rsslibj-
Export 0rc2.jar and the EXMLjar files it requires, and then copy to web/WEB-INF/lib.
 
Rsslibj-1_0RC2.jar: [url] http://sourceforge.net/project/downloading.php? Group_id = 71153 & use_mirror = nchc & filename = rsslibj-1_0RC2.jar & 27763931 [/url]
 
EXML. jar: [url] http://rsslibj.cvs.sourceforge.net/rsslibj/rsslibj/lib/EXML.jar? View = log [/url]
 
After downloading it, 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 = # \ '"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 (); importcom. rsslibj. elements. channel; publicclassWriter {publicstaticvoidmain (String [] args) throwsInstantiationException, ClassNotFoundException, IllegalAccessException {Channelchannel = newChannel (); channel. setDescription ("Thisismysamplechannel. "); channel. setLink ("/"); channel. setTitle ("MyChannel"); channel. setImage ("/", "TheChannelImage", "/foo.jpg"); channel. setTextInput ("/search", "SearchTheChannelImage", "TheChannelImage", "s"); channel. addItem ("/item1", "TheFirstItemcoversdetailsonthefirstitem>", "TheFirstItem "). setDcContributor ("Joseph PHB. ottinger "); channel. addItem ("/item2", "TheSecondItemcoversdetailsontheseconditem", "TheSecondItem "). setDcCreator ("JasonBell"); System. out. println ("ThefeedinRDF:" channel. getFeed ("rdf "));}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.