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(); }
原文链接:https://www.f2er.com/xml/295133.html