zoukankan      html  css  js  c++  java
  • 微信 xml 转 Map

    String xml = "<?xml version="1.0" encoding="UTF-8"?>";
            xml += "<xml><ToUserName><![CDATA[gh_d98e72ec57f1]]></ToUserName>";
            xml += "<FromUserName><![CDATA[otNn0jrHVLwKQj60drFhWgpUWjt0]]></FromUserName>";
            xml += "<CreateTime>1429066940</CreateTime>";
            xml += "<MsgType><![CDATA[event]]></MsgType>";
            xml += "<Event><![CDATA[scancode_waitmsg]]></Event>";
            xml += "<EventKey><![CDATA[key_8a88136e4cbad2d0014cbaf5a90f001a]]></EventKey>";
            xml += "<ScanCodeInfo><ScanType><![CDATA[qrcode]]></ScanType>";
            xml += "<ScanResult><![CDATA[BD1001/420010/320010/8500BF00123456/1.31/30.2/120G/4G/INTEL E7200 2.53G]]></ScanResult>";
            xml += "</ScanCodeInfo>";
            xml += "</xml>";
            
            try {
                Map<String, String> map = new HashMap<String, String>();
                Document document = DocumentHelper.parseText(xml);
                // 得到xml根元素
                Element root = document.getRootElement();
                // 得到根元素的所有子节点
                List<Element> elementList = root.elements();
    
                // 遍历所有子节点
                for (Element e : elementList) {
                    List<Element> elementLists = e.elements();
                    if (elementLists.size() > 0) {
                        for (Element es : elementLists) {
                            map.put(es.getName(), es.getText());
                        }
                    } else {
                        map.put(e.getName(), e.getText());
                    }
                }
    
                for (String key : map.keySet()) {
                    logger.warn(key + " - key33 - " + map.get(key));
                }
            } catch (Exception ee) {
    
            }
  • 相关阅读:
    HTML th nowrap 属性
    C 语言实例 – 判断闰年
    Java MySQL 连接
    Linux shapecfg命令
    C 简介
    Java 之 HashSet 集合
    Java 之 Set 接口
    Java 之 LinkedList 集合
    Java 之 List 接口
    JavaScript 之 事件(详解)
  • 原文地址:https://www.cnblogs.com/xsmhero/p/4432212.html
Copyright © 2011-2022 走看看