package test;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class XmlTest {
public static void main(String[] args) {
File xmlFile=new File("test/xml.xml");
DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance();;//工厂模式实例化
try {
DocumentBuilder docmentBuilder=documentBuilderFactory.newDocumentBuilder();
Document document=docmentBuilder.parse(xmlFile);//加载文件
NodeList nodeList=document.getElementsByTagName("VALUE");//获取节点
for (int i = 0; i < nodeList.getLength(); i++) {
System.out.println(nodeList.item(i).getTextContent());
}
} catch (ParserConfigurationException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SAXException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}