Examples of RSS Parser (rome. jar and jdom. jar) in JAVA

Source: Internet
Author: User
Tags rss parser

1. The jdom. jar and rome. jar packages are required.
2. Create a project. The content of web. xml is as follows:

The Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.5"
Xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd>

<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
</Web-app>
 

3. Create an index. jsp with the following content:

The Code is as follows:
<% @ 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 () %> <Table border = 1 cellpadding = 3 width = "700">
<Tr>
<Th> Number </th>
<Th> Title </th>
<Th> Time www.111cn.net </th>
<Th> Content </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>
<Td> <% = entry. getDescription (). getValue () %> </td>
</Tr>
<%
}
%>
</Table>
</Div>
<Br>
</Body>
</Html>
 


4. Finished.

Rss reading package tool: http://share.weiyun.com/72ac26b22b846505dcc1e14a623abd8d

For more details, see: http://www.111cn.net/jsp/Java/58107.htm

Related Article

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.