gpt4 book ai didi

java - Saxon 交付 V1 Xpath 对象

转载 作者:行者123 更新时间:2023-12-02 09:09:09 26 4
gpt4 key购买 nike

我已经成功使用 SAXON HE 9.5.1-5 一段时间了。我们正在对平台中的某些版本的组件进行全面升级,其中包括迁移到 Saxon 9.8.0-8使用该版本代码失败。以下内容位于我们的 Spring beans 文件中:

    <bean id="xpathFactory" class="net.sf.saxon.xpath.XPathFactoryImpl" factory-method="newInstance"/>
<bean id="xpath" factory-bean="xpathFactory" factory-method="newXPath"/>
<bean id="myRequestValidator" class="gov.dhs.ice.prime.query.RequestValidator">
<constructor-arg index="0" ref="xpath"/>

如您所见,最后一个 bean 传递了“newXPath”方法的结果。为了进行调试,我获取传入对象的名称。使用 9.5.1-5 时,传入对象是 net.sf.saxon.xpath.XPathEvaluator 对象现在,在 9.8.0-8 中,我收到了 org.apache.xpath.jaxp.XPathImpl 对象

RequestValidator 程序然后将一些 XPath 编译作为构造函数的一部分。有了 XPathEvaluator 对象,一切都很好(就像一直以来一样)现在我得到了 org.apache.xpath.jaxp.XPathImpl 对象,当程序尝试编译 V2 XPath 语句时,构造函数会失败。 V1 工作正常。
那么,为什么这个新版本返回的对象与以前不同呢?

我确实尝试直接构建 net.sf.saxon.xpath.XPathEvaluator..

    <bean id="xpath" class="net.sf.saxon.xpath.XPathEvaluator"/>
<bean id="myRequestValidator" class="gov.dhs.ice.prime.query.RequestValidator">
<constructor-arg index="0" ref="xpath"/>

这适用于新版本。但是,文档似乎推荐早​​期的方法。

有什么想法吗?谢谢

最佳答案

某些版本的 Saxon 不再将自身注册为 JAXP XPathFactory,请参阅 http://saxonica.com/html/documentation9.8/xpath-api/jaxp-xpath/factory.html :

The JAXP API is designed on the basis that when your application invokes XPathFactory.newInstance(), an XPath engine is selected by examining the values of system properties and searching the classpath. If you rely on this mechanism, then your application may end up running with an XPath engine on which it has never been tested. Since different XPath engines can differ in many significant respects (most notably, the version of XPath that they support), this can easily lead to application failures. Saxon therefore no longer identifies itself (in the JAR file manifest) as a JAXP XPath supplier. If you want to load Saxon as your XPath engine, you need to select it explicitly; it's not enough to just put it on the classpath

您认为在 net.sf.saxon.xpath.XPathFactoryImpl 上调用的 newInstance 方法实际上是抽象基类 https://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance-- 的方法。这就是调用另一个重载 https://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance-java.lang.String-应该加载 JAXP 注册的 XPathFactory 的基类。

所以你应该做的是:“如果你想使用 Saxon 作为 XPath 实现,你必须直接实例化类 net.sf.saxon.xpath.XPathFactoryImpl。”,例如在 Java 代码中 new net.sf.saxon.xpath.XPathFactoryImpl()

我不确定这是如何以 bean 语法声明方式表达的,但也许您知道这一点,或者其他人可以提供帮助。

关于java - Saxon 交付 V1 Xpath 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59547740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com