Basic use of RSS – Rsslibj

RSS, everyone should have seen it, and some students may use it frequently. Here is a brief share of your understanding of RSS.

1. Introduction to RSS

RSS (Simple Information Aggregation) is a format specification for news sources that is used to aggregate frequently updated data Websites, such as web digests of blog posts, news, audio or video. RSS files (also called abstracts, web abstracts, or

frequently updated, provided to the channel) contain the full text or excerpts, plus the web summary data and authorization subscribed by the sender Metadata.

Really Simple Syndication “Aggregation is really simple” is the original meaning of RSS in English. The purpose of RSS is to “send” news headlines, feeds, and content to the user’s desktop according to the user’s requirements. The term RSS sometimes

still generally means social bookmarking, including various RSS formats. For example, Blogspace labels RSS info and RSS reader for the actions of using the web digest in an integrator. Although its first sentence contains a clear

Atom format: “RSS and Atom files can update information from the website to your computer in a simple format!”

< br> RSS feeds can be read through web pages such as RSS readers, feed readers, or aggregators, or desktop-based software. The standard XML file format allows information to be viewed through different programs after one release. The user

subscribes to the feed by entering the feed into the RSS reader or using the mouse to click the URI (not usually called the URL) of the small RSS icon on the browser that points to the subscription program. The RSS reader regularly checks for updates, and then downloads them to the monitoring user

interface.

—-Excerpt from “Wikipedia”

The basic format of RSS:

  RSS Title This is an example of an RSS feed http://www.someexamplerssdomain.com/main.html  Mon, 06 Sep 2010 00:01:00 +0000  Mon, 06 Sep 2009 16:20:00 +0000  1800  Example entry Here is some text containing an interesting description. http://www.wikipedia.org/ unique string per item < pubDate>Mon, 06 Sep 2009 16:20:00 +0000   

Detailed description of RSS format You can see here:

http://cyber.law.harvard.edu/rss/rss.html

2. Resolve RSS

< p> Let me talk about it first, we already know an RSS address, how to resolve her.

Let’s take People’s Network: http://www.people.com.cn/rss/politics.xml as an example.

 public String parseRss() throws Exception {//Analyze RSS according to URL and convert String URL url = new URL(rssUrl); InputStream inputstream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream)); StringBuilder data = new StringBuilder(); String line = null; while( (line = reader.readLine()) != null) {data.append(line);} reader.close(); inputstream.close(); //parse string parse(data.toString()); return SUCCESS;} 

We will pass the URL, read line by line to the data, and then use rsslibj to parse

 private void parse(String data) throws ParseException {StringReader reader = new StringReader(data); // Create RSSReader for RSS reading object rssReader = new RSSReader(); // Set read content rssReader.setReader( reader); channel = rssReader.getChannel(); }

 private String rssUrl; //RSS address private Channel channel; //RSS entity

pre>
Through this Channel, we can read the information in RSS.

 

Analysis result

Description:
Link: "> < br/> Content:
Title:
Author:
Description:
Link: ">

After parsing, it looks like this:

PS: I have briefly talked about it here. If I use it in the future, I will learn more.

3. Generate RSS

We can already implement the analysis simply, let’s learn how to generate it below.

 public String createRss() throws Exception{ String rssData = create(); response.setContentType("text/xml;charset= utf-8"); PrintWriter out = response.getWriter(); out.println(rssData); out.flush(); out.close(); return NONE; }

 private String create() throws InstantiationException, IllegalAccessException, ClassNotFoundException {Channel channel = new Channel(); channel.setDescription("Ha, I just want to test it"); 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 o n the second item", "The Second Item").setDcCreator("Jason Bell"); return channel.getFeed("2.0"); }

The display interface is like this:

Okay, let’s just say so much, awaiting in-depth research in the future.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1802 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.