Here you can find the source of XPathAPI_selectNodeList(Document doc, String xpath, Node namespaceNode)
private static NodeList XPathAPI_selectNodeList(Document doc, String xpath, Node namespaceNode) throws TransformerException
//package com.java2s; import java.util.Iterator; import javax.xml.transform.TransformerException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* ww w. j av a 2 s . co m*/ * Compatibility. * * @param node * @param xpath * @return * @throws TransformerException */ private static NodeList XPathAPI_selectNodeList(Node node, String xpath) throws TransformerException { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); setNamespace(xPath, xpath); try { XPathExpression xPathExpression = xPath.compile(xpath); return (NodeList) xPathExpression.evaluate(node, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new TransformerException( "Exception in XPathAPI_selectNodeList: " + xpath, e); } } private static NodeList XPathAPI_selectNodeList(Document doc, String xpath, Node namespaceNode) throws TransformerException { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); setNamespace(xPath, xpath); try { XPathExpression xPathExpression = xPath.compile(xpath); return (NodeList) xPathExpression.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new TransformerException( "Exception in XPathAPI_selectNodeList: " + xpath, e); } } private static NodeList XPathAPI_selectNodeList(Node context, String xpath, Node namespaceNode) throws TransformerException { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); setNamespace(xPath, xpath); try { XPathExpression xPathExpression = xPath.compile(xpath); return (NodeList) xPathExpression.evaluate(context, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new TransformerException( "Exception in XPathAPI_selectNodeList: " + xpath, e); } } private static void setNamespace(XPath xpath, String string) { if (string.contains("special/icu:")) { xpath.setNamespaceContext(new javax.xml.namespace.NamespaceContext() { public String getNamespaceURI(String prefix) { if (prefix.equals("icu")) { return "http://www.icu-project.org"; } return null; } public String getPrefix(String namespaceURI) { return null; } public Iterator<Object> getPrefixes(String namespaceURI) { return null; } }); } } }