xml2map map2xml

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

 

posted @ 2017-03-07 20:30  yangfei969  阅读(341)  评论(0编辑  收藏  举报