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:Submitte开发者_开发百科r/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,
Roytry this...it works fine in 2.8-SNAPSHOT
.setHeader(Exchange.FILE_NAME,
XPathBuilder.xpath("normalize-space(//rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId/text()", String.class))
Have you tried: normalize-space(//rm:TradeMsg/rm:Submitter/rm:partyTradeIdentifier/fpml:tradeId) ?
精彩评论