美文网首页
Java解析XML文件

Java解析XML文件

作者: 小肥肥哒 | 来源:发表于2018-11-06 18:54 被阅读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();

            }

    }

    }

    相关文章

      网友评论

          本文标题:Java解析XML文件

          本文链接:https://www.haomeiwen.com/subject/nrfpxqtx.html