Strange XPath behaviour using xpath-transformer - tags lost
I'm just trying to understand the different behaviour between a xpath-splitter and a xpath-transformer
I have a requirement where I need to extract the inner part of message (as the xml payload I need is wrapped in an another xml document that has an xs:any node)
abbreviated example (with namespaces omitted)
Code:
<rootDoc>
<transport>
</transport>
<payload>
<!-- nested document starts here -->
<document>
<name>myname</name>
<id>123456</id>
</document>
</payload>
</rootDoc>
So initially I thought 'xpath-transformer' would do the job. But the result is the Payload contains a String with the textual values of the nested document, but no tags are present around the data - just empty spaces where tags should be :-
myname
123456
Code:
<int-xml:xpath-transformer id="xpath-transformer-extract-payload"
input-channel="testXpathChannel"
output-channel="extractedPayloadChannel"
xpath-expression-ref="xpathExtractPayload"
evaluation-type="STRING_RESULT"/>
<int-xml:xpath-expression id="xpathExtractPayload"
expression="/rootDoc/payload"
namespace-map="namespaceMapSubmission" />
So note: this is using
evaluation-type="STRING_RESULT"
however if instead I choose
evaluation-type="NODE_RESULT"
then the Payload result is of Type: DeferredElementNSImpl which if logged shows: [payload: null]
which I assume is no good to the next step in my processing - which is an xml unmarshall.
So given this was not working I instead tried an xpath-splitter :-
Code:
<int-xml:xpath-splitter id="itemSplitterTest"
input-channel="testXpathChannel"
output-channel="extractedPayloadChannel">
<int-xml:xpath-expression expression="/rootDoc/payload"
namespace-map="namespaceMapSubmission" />
</int-xml:xpath-splitter>
This seems to work fine, the resulting payload is a String, however I'm not that happy with the solution as a splitter feels wrong - as I'm only splitting into 1 item, so it's really a transformation thats required.
What I did deduce is that when a xpath-splitter is used the spring code will do a :-
Code:
transformer.transform(new DOMSource(nodeFromList), result);
in the splitDocument() method of the XPathMessageSplitter which seems to do the trick.
Any thoughts on what's going on ?