XML格式转为map格式

/**    
 * XML格式转为map格式     
 * @param request    
 * @return     
 */    
    public static Map xmlToMap(HttpServletRequest request){                
           Map map = new HashMap();        
           try {            
               InputStream inputStream =null;
               inputStream = request.getInputStream();
               SAXReader reader = new SAXReader();
               Document doc = reader.read(inputStream);
               Element rootElement = doc.getRootElement();
               List elements = rootElement.elements();
               for (Element el:elements) {
                   map.put(el.getName() , el.getText());
               }
               inputStream.close();
               return map ;
           } catch (Exception e) {
               e.printStackTrace();
               return null ;
           }

 

你可能感兴趣的:(随笔,Document)