【发布时间】:2014-12-02 09:17:06
【问题描述】:
我找到了这个Using Xalan alongside Saxon,但我没有让它工作。
我在我的pom.xml 中插入camel-saxon 的依赖项
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-saxon</artifactId>
<version>2.14.0</version>
</dependency>
并得到这个错误:
java.util.ArrayList cannot be cast to org.w3c.dom.NodeList
在此代码中:
public NodeList getXPathFromFile(String xpathStr, String xmlfile) {
NodeList nodes = null;
try {
System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":"
+ XPathFactory.DEFAULT_OBJECT_MODEL_URI,
"org.apache.xpath.jaxp.XPathFactoryImpl");
XPathFactory jaxpFactory = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI);
XPath xpath = jaxpFactory.newXPath(); /*XPathFactory.newInstance()*/
String expression = xpathStr;
InputSource inputSource = new InputSource(xmlfile);
nodes = (NodeList) xpath.compile(expression).evaluate(inputSource, XPathConstants.NODESET); <-- here come's the error
} catch (XPathExpressionException | XPathFactoryConfigurationException e) {
e.printStackTrace();
}
return nodes;
}
如果我删除依赖项,我的代码运行良好。但是我的骆驼路线需要 xslt 2.0,并且不想更改我的代码。我错了什么?
我需要导入一些东西吗?
【问题讨论】:
标签: xslt xpath apache-camel saxon xalan