Saxon无法编译xPath

时间:2016-04-05 14:18:05

标签: java xpath saxon

我构建saxon9-7-0-4source.zip并尝试根据以下xml在dom4j文档中执行xPath .//item[@name='entry']//property[matches(@value,'test[0-9]{1,2}$')]/..

<root>
<item name="abc">
  <iitem>
    <property value="test"/>
  </iitem>
</item>
<item name="entry">
  <iitem>
    <property value="test"/>
  </iitem>
  <iitem>
    <iiitem>
      <property value="test12"/>
    </iiitem>
  </iitem>
  <iitem>
    <property value="123"/>
  </iitem>
</item>
</root>

xPath做我想象的,我在http://www.qutoric.com/xslt/analyser/xpathtool.html

在线测试

但是如果我在我的java代码中尝试相同的话

        Processor proc = new Processor(false);
        proc.getUnderlyingConfiguration().registerExternalObjectModel(new DOM4JObjectModel());
        DocumentBuilder db = proc.newDocumentBuilder();
        XdmNode xdmDoc = db.wrap(doc4j);
        XPathCompiler xpath = proc.newXPathCompiler();
        String path=".//item[@name='entry']//property[matches(@value,'test[0-9]{1,2}$')]/..";
        XPathExecutable viewPath = xpath.compile(path);

我在线程&#34; main&#34;中遇到意外错误异常

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Cannot instantiate the type SystemFunctionCall

    at net.sf.saxon.functions.SystemFunction.makeFunctionCall(SystemFunction.java:94)
    at net.sf.saxon.functions.RegexFunction.makeFunctionCall(RegexFunction.java:69)
    at net.sf.saxon.functions.RegexFunctionSansFlags.makeFunctionCall(RegexFunctionSansFlags.java:49)
    at net.sf.saxon.functions.SystemFunctionLibrary.bind(SystemFunctionLibrary.java:91)
    at net.sf.saxon.functions.FunctionLibraryList.bind(FunctionLibraryList.java:105)
    at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:3015)
    at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2005)
    at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:1890)
    at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1815)
    at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1777)
    at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1791)
    at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1666)
    at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:653)
    at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:592)
    at net.sf.saxon.expr.parser.XPathParser.parsePredicate(XPathParser.java:1958)
    at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:1900)
    at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1820)
    at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1777)
    at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1791)
    at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1666)
    at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:653)
    at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:592)
    at net.sf.saxon.expr.parser.XPathParser.parse(XPathParser.java:464)
    at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:98)
    at net.sf.saxon.sxpath.XPathEvaluator.createExpression(XPathEvaluator.java:144)
    at net.sf.saxon.s9api.XPathCompiler.internalCompile(XPathCompiler.java:506)
    at net.sf.saxon.s9api.XPathCompiler.compile(XPathCompiler.java:481)
    at xslt.XSLT.main(XSLT.java:35)

如果我尝试通过XPathExecutable viewPath = xpath.compile(path);编译xPath,则会发生此错误。

1 个答案:

答案 0 :(得分:0)

I figured out the reason where this Exception comes from. My version of eclipse is to old like it is described here. I have to compile saxon 9.7 against java 8.