0

What is easiest way in Mule to loop through all nodes in xml payload and get values of each node

JvaDev
  • 1
  • 2

2 Answers2

0

Not sure if I understand it correctly. What do you want to do with each value?

You could use the xpath3() method in mule to get xml elements from payload. Here's an example flow which uses xpath3 to get the value of a xml element:

<flow name="print-payloadFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <set-payload value="#['&lt;note&gt;&lt;to&gt;Tove&lt;/to&gt;&lt;from&gt;Jani&lt;/from&gt;&lt;heading&gt;Reminder&lt;/heading&gt;&lt;body&gt;Dont forget me this weekend!&lt;/body&gt;&lt;/note&gt;']" doc:name="Set Payload"/>
    <logger message="#[xpath3('//from')]" level="INFO" doc:name="Logger"/>
</flow>

can't paste the whole mule flow because I don't have the reputation to post links so I am not allowed to post whole xml files ;-)

just create a new mule flow and paste this snippet to it if you want to test it.

  • Thank you very much for your response. I want to see if value of that node match to a specific string (eg. 'node_to_be_updated') and if it is then add some attributes to that node which has got that specific string as a value. – JvaDev Oct 15 '16 at 18:02
0

As you did not put your entire requirement correctly, there are various solution already listed On, please refer below links.

Refer below links which will give you enough insight to solve your problem.

Mule Using XPath to return a value out of an Payload

foreach in xml-node return null in mule esb

How to extract values from an xml list in Mule foreach

How to extract a node value from an xml in Mule

MULE: xpath expression not extracting values from payload

Community
  • 1
  • 1
Alpesh Gediya
  • 3,706
  • 1
  • 25
  • 38
  • Thank you very much for pointers. My actual requirement is to search for specific string in the incoming xml payload and add some attributes to all those nodes which has got that specific string as a value. I will go through suggested links and see if I can use those technics to achieve expected result. – JvaDev Oct 15 '16 at 17:58