问题
I am using below flow.
<flow name="mytestFlow1" doc:name="mytestFlow1">
<http:inbound-endpoint mimeType="text/xml" path="xmltest" exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<foreach collection="#[xpath://file//data//deliveryOrder]" doc:name="For Each" >
<echo-component />
<logger level="INFO" message="#[payload]" />
<logger level="INFO" message="#[rootMessage]" />
</foreach>
</flow>
and posting below xml.
<file>
<data>
<deliveryOrder>
<deliveryMethod>TRUCK1</deliveryMethod>
</deliveryOrder>
<deliveryOrder>
<deliveryMethod>TRUCK21</deliveryMethod>
</deliveryOrder>
<deliveryOrder>
<deliveryMethod>TRUCK2</deliveryMethod>
</deliveryOrder>
</data>
</file>
when I am running my flow echo component is print correct but logger print null. I also used custom transformer it also print null.
Any suggestion is appreciate.
回答1:
Try the following ... you will get All the values of <deliveryMethod>
<flow name="mytestFlow1" doc:name="mytestFlow1">
<http:inbound-endpoint
mimeType="text/xml"
path="xmltest"
exchange-pattern="request-response"
host="localhost"
port="8081"
doc:name="HTTP"/>
<splitter
evaluator="xpath"
expression="//file/data/deliveryOrder"
doc:name="Splitter_For_MultipleSameNodes"/>
<logger level="INFO"
message="#[xpath('//deliveryMethod').text]"
doc:name="Logger"/>
</flow>
回答2:
Problem is sort out using convert it to json first.
<json:xml-to-json-transformer doc:name="XML to JSON" />
<foreach doc:name="For Each" collection="#[json:file/data/deliveryOrder]">
<flow-ref name="insertdatabase" doc:name="Flow Reference" />
</foreach>
来源:https://stackoverflow.com/questions/26689970/foreach-in-xml-node-return-null-in-mule-esb