public static Map<String, String> xmlToMap(HttpServletRequest request) throws IOException, DocumentException{ Map<String, String> map = new HashMap<String, String>(); SAXReader reader = new SAXReader(); InputStream ins = request.getInputStream(); Document doc = reader.read(ins); Element root = doc.getRootElement(); List<Element> list = root.elements(); for(Element e : list){ map.put(e.getName(), e.getText()); } ins.close(); return map; }
public static String textMessageToXml(TextMessage textMessage){ XStream xstream = new XStream(); xstream.alias("xml", textMessage.getClass()); return xstream.toXML(textMessage); }