修剪 Camel 路由中使用的 xpath 表达式
这可能是骆驼问题或 xpath 问题:)。非camel人员请注意:camel使用javax.xml.xpath来解析他们的xml。
在骆驼路线中,我试图从 xml 主体中提取一个元素用作我的文件名:
Namespaces ns = getNamespaces();
String fileIDxPath = (see notes);
from("direct:testOutToFile")
.setHeader(Exchange.FILE_NAME, ns.xpath(fileIDxPath))
.to("file:/tmp/testing/generatedXML");
但我似乎无法获得一个 xpath 来为我提供节点的修剪值 。这是我尝试过的 xpath:
A) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/
B) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text()
C) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text()[normalize-space()]
D) normalize-space(//rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text())
- A) 返回整个节点,而不仅仅是值
- B) 返回值,但包含大量空格
- C) 还返回包含所有空格的值
- D) 抛出 XPathExpressionException
问题对于 xpath 专家来说 - 我是否在 xpath 中遗漏了一些可以修剪此值的内容?
骆驼专家的问题 - 也许我可以在评估后修剪这个值?我知道我可以通过另一个步骤来传递它,但我认为这将是一个足够常见的用例,可以在 ns.xpath 调用本身中得到支持。
我还注意到 ns.xpath 将标头设置为“com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList”的实例,而不是 String,这将是预期的类型。
谢谢大家,
罗伊
This might be either a camel or an xpath question :). Note to non-camel folks: camel uses javax.xml.xpath to resolve their xml.
In a camel route, I'm trying to pull an element out of the xml body to use as my filename:
Namespaces ns = getNamespaces();
String fileIDxPath = (see notes);
from("direct:testOutToFile")
.setHeader(Exchange.FILE_NAME, ns.xpath(fileIDxPath))
.to("file:/tmp/testing/generatedXML");
But I can't seem to get an xpath that gives me the trimmed value of the node. Here's the xpath that I've tried:
A) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/
B) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text()
C) //rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text()[normalize-space()]
D) normalize-space(//rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text())
- A) Returns the whole node, not just the value
- B) Returns the value, but with loads of whitespace
- C) Also returns the value with all of the whitespace
- D) Throws XPathExpressionException
Question for xpath gurus - am I missing something in my xpath that would trim this value?
Question for camel gurus - maybe I can trim this value after it's evaluated? I know I could pass it through another step, but I'd think that this would be a common enough use case to be supported in the ns.xpath call itself.
I also noticed that the ns.xpath sets the header to an instance of 'com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList' instead String, which would be the expected type.
Thanks all,
Roy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个...它在 2.8-SNAPSHOT 中工作正常
try this...it works fine in 2.8-SNAPSHOT
你有没有尝试过:
标准化空间(//rm:TradeMsg/rm:提交者/rm:partyTradeIdentifier/fpml:tradeId)
?
Have you tried:
normalize-space(//rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId)
?