教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 JAVA中RSS解析器(rome.jar和jdom.jar)范例

JAVA中RSS解析器(rome.jar和jdom.jar)范例

发布时间:2016-11-25   编辑:jiaochengji.com
教程集为您提供JAVA中RSS解析器(rome.jar和jdom.jar)范例等资源,欢迎您收藏本站,我们将为您提供最新的JAVA中RSS解析器(rome.jar和jdom.jar)范例资源
在使用此例子之前我们在文章最底部下载rome.jar和jdom.jar工具包才可以哦,准备好了就可以测试下面的例子了,希望文章对你会有帮助。

1.需要 jdom.jar 和 rome.jar 这两个包。
2.创建一个项目,web.xml的内容如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2830')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2830>

<?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.创建一个index.jsp 内容如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5273')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5273>

<%@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>
                <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.完工。

rss读取包工具:http://share.weiyun.com/72ac26b22b846505dcc1e14a623abd8d

您可能感兴趣的文章:
JAVA中RSS解析器(rome.jar和jdom.jar)范例
jQuery的RSS解析器 jFeed
结合使用PHP和RSS
PHP和AJAX打造高级RSS聚合器
精选PHP中常用的20个类库
利用PHP和AJAX创建RSS聚合器(一)
java入门篇-数据类型
提高CSS文件可维护性的五种方法
.Net/C#: 利用反射编写通用的 rss 2.0 的 reader
提高css div布局的可读性

[关闭]
~ ~