Java tutorial
//package com.java2s; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import java.util.Arrays; import java.util.Iterator; public class Main { private static final ThreadLocal<XPath> schemaXPathThreadLocal = new ThreadLocal<>(); public static XPath getSchemaXPath() { XPath xPath = schemaXPathThreadLocal.get(); if (xPath == null) { xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String prefix) { return XMLConstants.W3C_XML_SCHEMA_NS_URI; } @Override public String getPrefix(String namespaceURI) { return "xs"; } @Override public Iterator getPrefixes(String namespaceURI) { return Arrays.asList("xs").iterator(); } }); schemaXPathThreadLocal.set(xPath); } return xPath; } }