Java tutorial
/* * MessageUtil.java * Created on 20161011 ?10:49:46 * Copyright (c) ??? All Rights Reserved. * http://www.upsoft.com.cn * * This software is the confidential and proprietary information of UPSoft. * You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with UPSoft. */ package com.ischool.weixin.tool; import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; /** * Copyright (c) 2016,???<br> * All rights reserved.<br> * * ??MessageUtil.java<br> * ????<br> * -------------------------------------------------------<br> * ?1.1.1<br> * ??<br> * ?20161011<br> * -------------------------------------------------------<br> * ?1.1.0<br> * ??<br> * ?20161011<br> */ public class MessageUtil { public static Map<String, String> parseXml(HttpServletRequest request) throws Exception { // ?HashMap Map<String, String> map = new HashMap<String, String>(); // request?? InputStream inputStream = request.getInputStream(); // ?? SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); // xml Element root = document.getRootElement(); // ? @SuppressWarnings("unchecked") List<Element> elementList = root.elements(); // ??? for (Element e : elementList) { map.put(e.getName(), e.getText()); } // ? inputStream.close(); inputStream = null; return map; } }