问答详情
源自:2-1 图文消息

xmlToMap这个方法能不能给我贴出来

老师xml转换map的方法给发一下

提问者:愿你温暖似阳光丶 2018-09-04 15:11

个回答

  • happyxixi
    2018-09-05 16:39:07

    public static Map<String,String> xmlToMap(HttpServletRequest req) throws IOException, DocumentException{

    Map<String,String> map = new HashMap<String, String>();

    InputStream  is = req.getInputStream();

    SAXReader reader = new SAXReader();

    Document doc = reader.read(is);

    Element root = doc.getRootElement();

    List<Element> elements = root.elements();

    for(Element e:elements){

    map.put(e.getName(), e.getText());

    }

    is.close();

    return map;

    }