Java解析XML文件
importjava.io.*;
importjava.util.*;
importorg.dom4j.*;
importorg.dom4j.io.*;
publicclassReadXML {
publicstaticvoidmain(String arge[]) {
try{
File f = newFile("pom.xml");
SAXReader reader = newSAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Element contactElem = root.element("dependencies");
List<Element> contactList = contactElem.elements();
for(Element e:contactList){
if(e.elementText("groupId").equals("org.apache.httpcomponents")&&e.elementText("artifactId").equals("httpclient")){
System.out.println(e.elementText("version"));
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}