XPath找不到引擎

时间:2009-02-09 15:02:39

标签: java xpath

我继承了一些使用XPath的代码,我是新手。我现在有它,以便它加载文档,但是当document.selectPath(queryPath)它总是失败时出现以下错误:

java.lang.RuntimeException:  Trying XBeans path engine... Trying XQRL... Trying delegated path engine... FAILED on //
        at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:173)
        at org.apache.xmlbeans.impl.store.Path.getCompiledPath(Path.java:130)
        at org.apache.xmlbeans.impl.store.Cursor._selectPath(Cursor.java:902)
        at org.apache.xmlbeans.impl.store.Cursor.selectPath(Cursor.java:2634)
        at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:462)
        at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:446)

3 个答案:

答案 0 :(得分:3)

谢谢jor的帖子。我很困惑,因为早期的xml bean命令是成功的。

没有撒克逊,这仍然有效:

MapDocument doc;
...
String cityQuery = "$this//City";
XmlObject[] cities = doc.selectPath(cityQuery);

但是,在标签中明确选择字段需要使用saxon:

String aveQuery= "$this//Street[Kind='Avenue']";
XmlObject[] avenues = doc.selectPath(aveQuery); // RuntimeException without saxon on path

java.lang.RuntimeException:
Trying XBeans path engine... Trying XQRL... Trying delegated path engine... FAILED on $this//Street[Kind='Avenue']

我希望这可能对遇到类似问题的其他人有用。

答案 1 :(得分:2)

您需要在类路径中使用XPath引擎,该引擎应该依赖于XMLBeans版本,请参阅 http://wiki.apache.org/xmlbeans/XmlBeansFaq#whatJars

答案 2 :(得分:2)

如果你的xpath中有[],那么它正在搜索外部xpath引擎...你必须下载saxonb9-0-0-4j& xmlbeans-xpath-2.4.0.jar并添加到类路径