Here you can find the source of createXPathExpression(String xpathString)
private static XPathExpression createXPathExpression(String xpathString)
//package com.java2s; /*//from ww w . ja v a 2s . co m * DSS - Digital Signature Services * * Copyright (C) 2011 European Commission, Directorate-General Internal Market and Services (DG MARKT), B-1049 Bruxelles/Brussel * * Developed by: 2011 ARHS Developments S.A. (rue Nicolas Bov? 2B, L-1253 Luxembourg) http://www.arhs-developments.com * * This file is part of the "DSS - Digital Signature Services" project. * * "DSS - Digital Signature Services" is free software: you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * DSS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with * "DSS - Digital Signature Services". If not, see <http://www.gnu.org/licenses/>. */ import java.util.Iterator; import javax.xml.crypto.dsig.XMLSignature; 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 XPathExpression createXPathExpression(String xpathString) { /* XPath */ XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); xpath.setNamespaceContext(new NamespaceContext() { @Override public Iterator<?> getPrefixes(String namespaceURI) { throw new RuntimeException(); } @Override public String getPrefix(String namespaceURI) { throw new RuntimeException(); } @Override public String getNamespaceURI(String prefix) { if ("ds".equals(prefix)) { return XMLSignature.XMLNS; } else if ("xades".equals(prefix)) { return "http://uri.etsi.org/01903/v1.3.2#"; } else if ("xades141".equals(prefix)) { return "http://uri.etsi.org/01903/v1.4.1#"; } else if ("xades111".equals(prefix)) { return "http://uri.etsi.org/01903/v1.1.1#"; } throw new RuntimeException("Prefix not recognized : " + prefix); } }); try { XPathExpression expr = xpath.compile(xpathString); return expr; } catch (XPathExpressionException ex) { throw new RuntimeException(ex); } } }