map2Xml

前端之家收集整理的这篇文章主要介绍了map2Xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
private static String imageTypeHandler(Map<String,String> msgMap,String mediaid) {
Map<String,String> map=new HashMap<String,String>();
map.put("ToUserName",msgMap.get("FromUserName"));
map.put("FromUserName",msgMap.get("ToUserName"));
map.put("CreateTime",new Date().getTime()+"");
map.put("MsgType","image");
map.put("Image","<MediaId>"+mediaid+"</MediaId>");

return map2Xml(map);

}


private static String map2Xml(Map<String,String> map) { Document document=DocumentHelper.createDocument(); Element root=document.addElement("xml"); Set<String> keys=map.keySet(); for(String key:keys){ root.addElement(key).addText(map.get(key)); } StringWriter sw=new StringWriter(); XMLWriter xw=new XMLWriter(sw); xw.setEscapeText(false); try { xw.write(document); } catch (IOException e) { e.printStackTrace(); } return sw.toString(); }

猜你在找的XML相关文章