public static Object executeXPath ( Node document , String xpathExpression , Map < String , String > namespaceMapping , QName result ) throws XPathException , MarshallingException { NamespaceMapContext mapContext = new NamespaceMapContext ( namespaceMapping ) ; try { XPathFactory xPathfactory = XPathFactory . newInstance ( ) ; XPath xpath = xPathfactory . newXPath ( ) ; xpath . setNamespaceContext ( mapContext ) ; XPathExpression expr = xpath . compile ( xpathExpression ) ; return executeXPath ( document , expr , result ) ; } catch ( XPathExpressionException e ) { throw new XPathException ( "Xpath(" + xpathExpression + ") cannot be compiled" , e ) ; } catch ( Exception e ) { throw new MarshallingException ( "Exception unmarshalling XML." , e ) ; } }
Executes the given xpath and returns the result with the type specified .