zoukankan      html  css  js  c++  java
  • 解析XML

    方式一:

    方式二:

    方式三:

    方式N:

    好可爱的demo:

    document.xml文件内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
        <node>
            <key1> value1</ key1>
            < key2> value 2</ key2>
            < key3> value 3</ key3>
        </node>
    
    
    
    public class ParseXml {
        public static Map<String, String> parseFile(String filePath) {
            File file = new File(filePath);
            if (!file.exists()) {
                return null;
            }
            try {
                Map<String, String> map = new HashMap<String, String>();
                //解析方式不限 
                SAXReader reader = new SAXReader();
                Document document = reader.read(file);
                Node node = document.selectSingleNode("node/key1");
                map.put("key1", node.getText());
                node = document.selectSingleNode("node/key2");
                map.put("key2", node.getText());
                node = document.selectSingleNode("node/key3");
                map.put("key", node.getText());
                return map;
            } catch (Exception e) {
                System.err.println("解析文件异常");
                e.printStackTrace();
                return null;
            }
        }
    
        public static void main(String[] args) {
            Map<String, String> resultMap = parseFile("D:/document.xml");
        }
    }
  • 相关阅读:
    ***CSS3 Gradient渐变色(转:http://www.w3cplus.com/content/css3-gradient)
    CSS3实现边框锯齿效果
    css3超炫8种loading加载特效
    CSS3:Transition属性详解
    WebApp之Meta标签
    css3渐变色
    转:CSS设置滚动条样式
    使用Composer安装 Laravel 和 ThinkPHP
    laravel 数据库迁移
    sublime text 3 常用插件和配置
  • 原文地址:https://www.cnblogs.com/alipayhutu/p/2498678.html
Copyright © 2011-2022 走看看