通过RSS把数据整合到一起。确实提供了很多方便。
不知道是不是自己太没有觉悟,没有用sourceforge上面的源码,自己用dom写了一个rss的读取器,代码列在下面吧。
package rssweb;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.CharacterData;
/**
* <p>Title: RSS页面显示bean</p>
*
* <p>Description: 通过调用该bean,实现在jsp中解析rss并在页面中显示</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: ui studio</p>
*
* @author uijiang
* @version 1.0
*/
public class ShowRSS {
//PreTitle存储RSS channel项目下的title名
public String PreTitle;
//itemList存储RSS的item项目下的title名
public String[] itemList;
//linkList存储RSS的的item项目下的link名
public String[] linkList;
//pubDateList存储RSS的的item项目下的pubDate名
public String[] pubDateList;
//descriptionList存储RSS的的item项目下的description名
public String[] descriptionList;
//itemCount记录读取出来的项目数
public int itemCount;
//不带参数的构造函数,不对各成员初始化,返回null
public ShowRSS() {
}
//将RSS地址以destination传入,实现读取操作,并为各成员变量赋值。
public ShowRSS(String destination) {
try {
//DOM初始化
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.
newInstance();
DocumentBuilder documentBuilder = dbFactory.newDocumentBuilder();
Document document = documentBuilder.parse(destination);
//得出item数量
NodeList nodelistCount = document.getElementsByTagName("item");
itemCount = nodelistCount.getLength();
//初始化各成员数组
itemList = new String[itemCount];
linkList = new String[itemCount];
pubDateList = new String[itemCount];
descriptionList = new String[itemCount];
//赋值计数
int _count = 0;
//获取title并为各成员变量赋值
NodeList nodelistTitle = document.getElementsByTagName("title");
for (int i = 0; i < nodelistTitle.getLength(); i++) {
Node node = nodelistTitle.item(i);
if (node.getParentNode().getNodeName().trim() == "channel") {
PreTitle = ((CharacterData) node.getFirstChild()).getData();
}
if (node.getParentNode().getNodeName().trim() == "item") {
itemList[_count++] = ((CharacterData) node.getFirstChild()).
getData();
}
}
//赋值计数
_count = 0;
//获取link并为各成员变量赋值
NodeList nodelistLink = document.getElementsByTagName("link");
for (int i = 0; i < nodelistLink.getLength(); i++) {
Node node = nodelistLink.item(i);
if (node.getParentNode().getNodeName().trim() == "item") {
linkList[_count++] = ((CharacterData) node.getFirstChild()).
getData();
}
}
//赋值计数
_count = 0;
//获取pubDataList并为各成员变量赋值
NodeList nodelistpubDate = document.getElementsByTagName("pubDate");
for (int i = 0; i < nodelistpubDate.getLength(); i++) {
Node node = nodelistpubDate.item(i);
if (node.getParentNode().getNodeName().trim() == "item") {
pubDateList[_count++] = ((CharacterData) node.getFirstChild()).
getData();
}
}
//赋值计数
_count = 0;
//获取pubDataList并为各成员变量赋值
NodeList nodelistDescription = document.getElementsByTagName(
"description");
for (int i = 0; i < nodelistDescription.getLength(); i++) {
Node node = nodelistDescription.item(i);
if (node.getParentNode().getNodeName().trim() == "item") {
descriptionList[_count++] = ((CharacterData) node.
getFirstChild()).
getData();
}
}
} catch (Exception e) {
}
}
}