foreach in xml-node return null in mule esb

大憨熊 提交于 2019-12-24 02:42:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!