日期:2014-05-16 浏览次数:20359 次
function callByXMLHttpRequest(url) { if (window.XMLHttpRequest){ req = new XMLHttpRequest(); } else if (window.ActiveXObject){ req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("Post",url,true); req.onreadystatechange = callback; var xmlStr = "<xml></xml>"; req.send(xmlStr); } function callback(data) { if(data.currentTarget.readyState == "4") { if(data.currentTarget.status == "200") { resolveXML($.parseXML(data.currentTarget.responseText)); } else { alert("网络不稳定,请稍后再试!"); } } }
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(); // 得到根元素的所有子节点 List<Element> elementList = root.elements(); // 遍历所有子节点 for (Element e : elementList) { map.put(e.getName(), e.getText()); } // 释放资源 inputStream.close(); inputStream = null; return map; }