Search code examples
xmlmulemule-studiomule-componentmule-el

iterate xml array request one by one before hitting webserviceconsumer


The complete request is :

 <?xml version='1.0' encoding='windows-1252'?>
<balanceInquiry>
    <request>
        <amount>
            <amount>1</amount>
            <currency>USD</currency>
        </amount>
    </request>
    <request>
        <amount>
            <amount>2</amount>
            <currency>USD</currency>
        </amount>
     </request>
     <request>
        <amount>
            <amount>3</amount>
            <currency>USD</currency>
        </amount>
      </request>
</balanceInquiry>

Before hitting to webconsumer it should be :

<balanceInquiry>
    <request>
        <amount>
            <amount>1</amount>
            <currency></currency>
        </amount>
    </request>
</balanceInquiry>

And then put response for 1 then again go for 2 and so on.

I am using a for each component like

<foreach collection="#[payload.balanceInquiry]" doc:name="For Each">
    <ws:consumer config-ref="Web_Service_Consumer" operation="balanceInquiry" doc:name="Web Service Consumer"/>
</foreach>

But its not working. Is there any other component available to perform the task or am I doing it wrong. Please suggest.


Solution

  • Use splitter to split your xml and then dom to xml transformer before making a web service call

    <splitter expression="#[xpath3('//balanceInquiry/request',payload,'NODESET')]"/>        
    <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>