Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt xalan和saxon同时在apache camel上_Xslt_Xpath_Apache Camel_Saxon_Xalan - Fatal编程技术网

Xslt xalan和saxon同时在apache camel上

Xslt xalan和saxon同时在apache camel上,xslt,xpath,apache-camel,saxon,xalan,Xslt,Xpath,Apache Camel,Saxon,Xalan,我找到了这个,但没用 我在我的pom.xml <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> <version>2.14.0</version> </dependency> 在此代码中: public NodeList getXPathFromFile(

我找到了这个,但没用

我在我的
pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-saxon</artifactId>
    <version>2.14.0</version>
</dependency>
在此代码中:

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;
    }
公共节点列表getXPathFromFile(字符串xpathStr,字符串xmlfile){ NodeList节点=null; 试一试{ System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME+):“ +XPathFactory.DEFAULT\u对象\u模型\u URI, “org.apache.xpath.jaxp.xpathfactorympl”); XPathFactory jaxpFactory=XPathFactory.newInstance(XPathFactory.DEFAULT\u OBJECT\u MODEL\u URI); XPath=jaxpFactory.newXPath();/*XPathFactory.newInstance()*/ 字符串表达式=xpathStr; InputSource InputSource=新的InputSource(xmlfile);
nodes=(NodeList)xpath.compile(expression).evaluate(inputSource,XPathConstants.NODESET);在我看来,似乎您选择的是Saxon作为xpath工厂(Saxon默认情况下为xpath inputSource构建自己的原生树,而不是DOM,因此返回Java列表中的节点,而不是DOM节点列表)

您真的确定每次执行XPath表达式时都要解析XML文件吗?因为代码就是这样做的

考虑到您的System.setProperty()设置,我不确定这段代码为什么会选择Saxon。Saxon在9.6版中已更改,因此它不再将自己注册为JAXP XPath工厂,从而消除了此问题(我们认为人们真的想知道他们得到的是XPath 1.0还是2.0处理器,XPath工厂机制为您提供了类路径上的任何处理器)

可能的解决办法是:

(a) 直接实例化ApacheXPath工厂,而不是依赖于JAXP类路径搜索(这非常昂贵,尤其是如果您只是为了计算单个XPath表达式而这样做的话)

(b) 将Saxon升级到9.6


(c)更改此代码,使其与Saxon配合使用。如果您不关心性能,最简单的更改是确保源文档作为DOMSource传递。虽然Saxon在使用DOM时要慢得多,但与每次执行XPa时创建XPath工厂和解析源文档的成本相比,这种低效率显得微不足道如果你想让整个过程更有效率,那就意味着要查看你展示给我们的片段之外的代码。

谢谢你的回答!是的,每次解析xml文件都可以,因为xml文件只加载一次。对于你的解决方案。b=不可能,因为apache camel与9.6不兼容。在c上,我正在工作,但是我对saxon和它的工作除了我需要的以外一无所知。或者我不知道如何做到这一点。我读了她更多的书。现在,这就是我想要一个快速解决方案的原因。但是我所有的实验都不起作用。你能告诉我,我如何从Apache XPath工厂直接实现实例吗?非常感谢(我是Java新手)只需将factory.newInstance()调用替换为
neworg.apache.xpath.jaxp.XPathFactoryImpl()
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;
    }