Java tutorial
//package com.java2s; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { public static XPathExpression compileExpression(final String xQuery) { if ((xQuery != null) && (xQuery.length() > 0)) { try { return XPathFactory.newInstance().newXPath().compile(xQuery); } catch (final XPathExpressionException e) { throw new RuntimeException(e); } } throw new RuntimeException("Query is null!"); } }