Here you can find the source of getXPath(String exp, NamespaceContext ctx)
public static XPathExpression getXPath(String exp, NamespaceContext ctx) throws XPathExpressionException
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; import javax.xml.namespace.NamespaceContext; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { private static ThreadLocal<Map<String, XPathExpression>> sCache = new ThreadLocal<Map<String, XPathExpression>>(); private static XPathFactory sFactory = XPathFactory.newInstance(); public static XPathExpression getXPath(String exp) throws XPathExpressionException { Map<String, XPathExpression> cache = getCache(); if (!cache.containsKey(exp)) { cache.put(exp, sFactory.newXPath().compile(exp)); }/* ww w.j a v a2s. com*/ return cache.get(exp); } public static XPathExpression getXPath(String exp, NamespaceContext ctx) throws XPathExpressionException { if (ctx == null) { return getXPath(exp); } XPath mRetVal = sFactory.newXPath(); mRetVal.setNamespaceContext(ctx); return mRetVal.compile(exp); } private static Map<String, XPathExpression> getCache() { Map<String, XPathExpression> mRetVal = sCache.get(); if (mRetVal == null) { mRetVal = new HashMap<String, XPathExpression>(); sCache.set(mRetVal); } return mRetVal; } }