Java tutorial
//package com.java2s; import java.io.InputStream; import java.util.HashMap; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; public class Main { private static DocumentBuilderFactory domFactory; private static XPathFactory xpathFactory; /** * Processes the POST request from the client instructing the server to process * a serverStart or serverProxy. Returns the fields in this request as a HashMap for * easy handling. * * @param xmlStream the InputStream obtained from an HttpServletRequest object. This contains the desired pipeline from the client. * @param search a HashMap with arbitrary names as keys and XPath Strings as values, the results of which are assigned as values to the names in the returned HashMap. * @return */ public static HashMap<String, String> procPipelineReq(InputStream xmlStream, HashMap<String, String> search) { HashMap<String, String> returnHash = new HashMap<String, String>(); try { for (String item : search.keySet()) { Document xmlDoc = parse(xmlStream); XPath xpath = xpathFactory.newXPath(); returnHash.put(item, xpath.evaluate(search.get(item), xmlDoc)); } } catch (Exception e) { e.printStackTrace(); } return returnHash; } public static Document parse(InputStream inputStream) throws Exception { return domFactory.newDocumentBuilder().parse(inputStream); } }