黑龙江

危机感-被淘汰

危机感-被淘汰

Valder Fields -- Tamas Wells

Valder Fields – Tamas Wells[flv width="257" height="33"]http://www.xiami.com/widget/5020_2080203/singlePlayer.swf[/flv]

简单的dom4j和xpth的使用

公司项目要解析xml文件,很简单的,也就需要一点点信息,用的是java本身的解析方式,很麻烦。我做了一个DEMO,使用了dom4j中的xpath,简单,想去哪里的信息就去哪里的信息,简单灵活。package com.inspur.eoms.pbb.open;import java.io.UnsupportedEncodingException;import java.util.List;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.Node;public class TestMain {public static void main(String[] args) throws UnsupportedEncodingException,DocumentException {StringBuffer sb1 = new StringBuffer();sb1.append("");sb1.append("0");sb1.append("失败原因");sb1.append("");sb1.append("");sb1.append("接入设备ID");sb1.append("接入设备类型");sb1.append("预占端口ID");sb1.append("预占端口名称");sb1.append("");sb1.append("");sb1.append("");Document doc = DocumentHelper.parseText(sb1.toString());List list = doc.selectNodes("/RESPONSE/RESULTS/RESULT/NAME");Element elm = (Element) list.get(0);System.out.println(elm.getText());list = doc.selectNodes("/RESPONSE/DESCRIPTION");elm = (Element) list.get(0);System.out.println(elm.getText());list = doc.selectNodes("/RESPONSE/RESULTS/RESULT");Node node = (Node) list.get(0);System.out.print(node.valueOf("@TYPE"));}}dom4j需要的jar包的地址http://www.box.net/shared/axb0oesgsu