JDOM 解析baidu新闻XML (二)

public class ReadXML {
public static void getRoot(String fileName){
//使用JDOM首先要指定使用什么解析器
SAXBuilder builder = new SAXBuilder();
//得到Document,我们以后要进行的所有操作都是对这个Document操作的
Document read_doc = builder.build(fileName);

//得到根元素
Element document = read_doc.getRootElement();
System.out.println();
System.out.println("---------NEWSXML--------------");
//读取根目录底下的一层
String webSiteList = document.getChildText("webSite");
String webMaster = document.getChildText("webMaster");
String updatePeri = document.getChildText("updatePeri");

System.out.println("webSite:"+webSiteList);
System.out.println("webMaster:"+webMaster);
System.out.println("updatePeri:"+updatePeri);
System.out.println("----------ITEM START-------------");
//得到元素(节点)的集合:
List itemlist = document.getChildren("item");
//轮循List集合
for(int i = 0;i < itemlist.size();i++) {

Element e = (Element)itemlist.get(i);
//取得元素的值
String title = e.getChildText("title");
String link = e.getChildText("link");
String text = e.getChildText("text");
String image = e.getChildText("image");
String headlineImg = e.getChildText("headlineImg");
String keywords = e.getChildText("keywords");
String category = e.getChildText("category");
String author = e.getChildText("author");
String source = e.getChildText("source");
String pubDate = e.getChildText("pubDate");


System.out.println("title:" + title);
System.out.println("link:" + link);
System.out.println("text:" + text);
System.out.println("image:"+image);
System.out.println("headlineImg:"+headlineImg);
System.out.println("keywords:"+keywords);
System.out.println("category:"+category);
System.out.println("author:"+author);
System.out.println("source:"+source);
System.out.println("pubDate:"+pubDate);

System.out.println("---------------ITEM END---------------");

}


System.out.println();
}
public static void main(String[] args) {
ReadXML.getRoot("d://newsXml.xml");
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值