zoukankan      html  css  js  c++  java
  • 使用Dom4j解析XML文件

    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>
  • 相关阅读:
    ASIX配置vlan tag能被wireshark获取
    翻译-cmake教程
    Manjaro打造开发环境
    Frida入门
    安卓应用启动底层执行逻辑
    集合框架
    oracle清除日志内存
    flutter widgets目录
    给设备添加udid
    5.class
  • 原文地址:https://www.cnblogs.com/menbo/p/10537816.html
Copyright © 2011-2022 走看看