<RESULT>
<VALUE>
<NO>A1234</NO>
<ADDR>四川省XX县XX镇XX路X段XX号</ADDR>
</VALUE>
<VALUE>
<NO>B1234</NO>
<ADDR>四川省XX市XX乡XX村XX组</ADDR>
</VALUE>
</RESULT>
public static void main(String arge[]) {
long lasting = System.currentTimeMillis();
try {
File f = new File("D://aa.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(f);
NodeList nl = doc.getElementsByTagName("VALUE");
for (int i = 0; i < nl.getLength(); i++) {
System.out.print("车牌号码:"
+ doc.getElementsByTagName("NO").item(i)
.getFirstChild().getNodeValue());
System.out.println("车主地址:"
+ doc.getElementsByTagName("ADDR").item(i)
.getFirstChild().getNodeValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
车牌号码:B1234车主地址:四川省XX市XX乡XX村XX组
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
//创建Builder,工厂new出来
DocumentBuilder builder = factory.newDocumentBuilder();
//开始解析 xml文件
Document doc = builder.parse(f);
//通过名字 找到节点或节点集合,
//下面就是取出需要的内容,前三布都是固定死的,不需要什么改变
//只需要花点功夫,把需要的数据取出来即可
//getElementsByTagName() 返回的是一个 NodeList对象
NodeList nl = doc.getElementsByTagName("VALUE");
// 输出 NO,NO节点