title: Using SAXON Xpath engine in Java
body: <p>Here is my code : </p>
  
  <pre><code>public static void main(String[] args) {
  
      // System.setProperty(
      // "javax.xml.xpath.XPathFactory", 
      // "net.sf.saxon.xpath.XPathFactoryImpl");
  
      String xml="&lt;root&gt;&lt;a&gt;#BBB#&lt;/a&gt;&lt;a&gt;#CCC#&lt;/a&gt;&lt;b&gt;&lt;a&gt;#DDD#&lt;/a&gt;&lt;/b&gt;&lt;/root&gt;";
      try{
          JDocument dom = new JDocument(xml);
  
          XPathFactory factory = net.sf.saxon.xpath.XPathFactoryImpl.newInstance();
          XPath xpath = factory.newXPath();
          XPathExpression expr = xpath.compile("//a[matches(.,'#...#')]");
  
          Object result = expr.evaluate(dom, XPathConstants.NODESET);
          NodeList nodes = (NodeList) result;
          Nodes sharped = new Nodes(nodes);
  
          for (Node n:sharped){
              System.out.println(n.toString());
          }
      }
      catch(Exception e){
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>And I get this : </p>
  
  <pre><code>javax.xml.transform.TransformerException: Impossible to find the function : matches
  at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:608)
  at org.apache.xpath.compiler.XPathParser.FunctionCall(XPathParser.java:1505)
  at org.apache.xpath.compiler.XPathParser.PrimaryExpr(XPathParser.java:1444)
  at org.apache.xpath.compiler.XPathParser.FilterExpr(XPathParser.java:1343)
  at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1276)
  </code></pre>
  
  <p>Which means Java is using <code>org.apache.xpath.compiler.XPathParser</code> class when I clearly created my factory through <code>net.sf.saxon.xpath.XPathFactoryImpl</code>.</p>
  
  <p>(I actually only need to put some <code>matches</code> in my xpaths... so if any solution not involving Saxon is known, consider my need reached).</p>
  
  <p>What am I doing wrong ?</p>