### Question:
XPathHelper { public static List<Node> getNodes(Node node, String xPath, Map<String, String> namespaces) { Validate.notNull(node, "node must not be null."); Validate.notEmpty(xPath, "xPath must not be empty."); List<Node> ret = new ArrayList<>(); XPathFactory factory = XPathFactory.newInstance(); XPath xPathObject = factory.newXPath(); MyNamespaceContext namespaceContext = new MyNamespaceContext(); namespaceContext.addNamespace("xhtml", XHTML_NAMESPACE); if (namespaces != null) { for (Entry<String, String> entry : namespaces.entrySet()) { String prefix = entry.getKey(); String uri = entry.getValue(); namespaceContext.addNamespace(prefix, uri); } } xPathObject.setNamespaceContext(namespaceContext); try { XPathExpression xPathExpression = xPathObject.compile(xPath); NodeList nodes = (NodeList) xPathExpression.evaluate(node, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { ret.add(nodes.item(i)); } } catch (XPathExpressionException e) { LOGGER.error("{} for XPath \"{}\" : {}", new Object[]{e, xPath, e.getMessage(), e}); } return ret; } private  XPathHelper(); static List<Node> getNodes(Node node, String xPath, Map<String, String> namespaces); static List<Node> getNodes(Node node, String xPath); static Node getNode(Node node, String xPath, Map<String, String> namespaces); static Node getNode(Node node, String xPath); static Node getNodeByID(Node node, String nodeId); static Node getParentNodeByID(Node node, String nodeId); static String getNodeTextContent(Node node, String xPath); static String getXhtmlNodeTextContent(Node node, String xPath); static String getParentXPath(String xPath); static List<Node> getPreviousSiblings(Node node); static List<Node> getXhtmlNodes(Document document, String xPath); static List<Node> getXhtmlNodes(Node node, String xPath); static Node getXhtmlNode(Document document, String xPath); static Node getXhtmlNode(Node node, String xPath); static boolean hasXhtmlNs(Document document); static String addXhtmlNsToXPath(Document document, String xPath); static String addXhtmlNsToXPath(String xPath);  }### Answer:
@Test public void testNamespace() throws ParserConfigurationException, SAXException, IOException { Document doc = ParseUtil.parseXhtml(ResourceHelper.getResourceFile("/multipleNamespaces.xml")); Map<String, String> mapping = new HashMap<String, String>(); mapping.put("h", "http: mapping.put("f", "http: List<Node> nodes = XPathHelper.getNodes(doc, " assertEquals(2, nodes.size()); nodes = XPathHelper.getNodes(doc, "/root/f:table/f:name", mapping); assertEquals(1, nodes.size()); }
@Test public void testGetNodes() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException { Document doc = ParseUtil.parseXhtml(ResourceHelper.getResourceFile("/w3c_xhtml_strict.html")); List<Node> tocNodes = XPathHelper.getXhtmlNodes(doc, " assertEquals(2, tocNodes.size()); Node firstTocNode = XPathHelper.getXhtmlNode(doc, " assertNotNull(firstTocNode); List<Node> tocItems = XPathHelper.getXhtmlNodes(firstTocNode, "ul/li"); assertEquals(10, tocItems.size()); List<Node> tocItems2 = XPathHelper.getXhtmlNodes(firstTocNode, "ul/*"); assertEquals(10, tocItems2.size()); }