menbbo

导航

 
public static String readXMl(){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
String s = null;
try{
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse("classpath:linuxFile.xml");
// s = document.getElementById("file").getNodeValue();
NodeList node = document.getElementsByTagName("temporary_file");
for (int i = 0;i<node.getLength();i++){
Element son = (Element)node.item(i);
for (Node node1 = son.getFirstChild(); node1 != null; node1 = node1.getNextSibling()){
if (node1.getNodeType() == Node.ELEMENT_NODE){
String name = node1.getNodeName();
String value = node1.getFirstChild().getNodeValue();
if(name.equals("filePath")){
s = value;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}


return s;
}
<?xml version="1.0" encoding="UTF-8"?>
<temporary_file>
<filePath>E:\ff</filePath>
</temporary_file>
posted on 2019-03-15 16:19  menbbo  阅读(80)  评论(0编辑  收藏  举报