我無法使xpath表達式正常工作。我正在使用駱駝2.15.1。任何幫助將不勝感激。駱駝使用xpath檢索xml標籤名稱
我已經試過以下
<xpath>name(//*[1])='PPR_PC2'</xpath>
<xpath>name("//*[local-name()='PPR_PC2')</xpath>
<xpath>//PPR_PC2</xpath>
我的XML文件
<?xml version="1.0" encoding="UTF-8"?>
<PPR_PC2 xmlns="urn:hl7-org:v2xml">
<MSH>
<MSH.1>|</MSH.1>
...
...
</MSH>
...
...
</PPR_PC2>
我的駱駝航線
<route id="_route_1">
<from uri="activemq:queue:myQIN"/>
<doTry>
<choice>
<when>
// This path works without having namespace
<xpath>name(//*[1])='PPR_PC2'</xpath>
<to uri="xslt:transform/stylesheet.xsl"/>
<to uri="..."/>
</when>
<otherwise> ... </otherwise>
</choice>
<doCatch> ... </doCatch>
</doTry>
</route>
這是我得到
[thread #1 - JmsConsumer[myQIN]] EndpointMessageListener
WARN Execution of JMS message listener failed.
Caused by: [org.apache.camel.builder.xml.InvalidXPathExpression - Invalid xpath: name(//*[1])='PPR_PC2'.
Reason: javax.xml.xpath.XPathExpressionException: net.sf.saxon.trans.XPathException:
A sequence of more than one item is not allowed as the first argument of name() (<PPR_PC2/>, <MSH/>, ...) ]
org.apache.camel.builder.xml.InvalidXPathExpression:
Invalid xpath: name(//*[1])='PPR_PC2'.
Reason: javax.xml.xpath.XPathExpressionException: net.sf.saxon.trans.XPathException:
A sequence of more than one item is not allowed as the first argument of name() (<PPR_PC2/>, <MSH/>, ...)
錯誤3210
謝謝邁克爾,那工作很好。 – user1998820