Java解析XML文件

2018-11-06  本文已影响0人  小肥肥哒

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();

        }

}

}

上一篇下一篇

猜你喜欢

热点阅读