微信 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() > ) {
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) { }
上一篇:关于WPF中Popup控件的小记


下一篇:ASP.NET WebForm中JavaScript修改了页面上Label的值,如何在后台代码中获取