首页 > 其他分享 >map2Xml

map2Xml

时间:2022-11-04 21:02:38浏览次数:84  
标签:map String Map map2Xml put new


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();
}


标签:map,String,Map,map2Xml,put,new
From: https://blog.51cto.com/u_10028442/5824747

相关文章