Search code examples
xmlmuleanypoint-studio

How can i get an element value from Payload XML in mule?


From this XML i want to get the id and set in a variable. Example : OrderID = 4258477000

 <?xml version="1.0" encoding="UTF-8"?>
    <order>
       <id type="integer">4258477000</id>
       <email>[email protected]</email>
       <closed-at type="dateTime" nil="true"/>
       <created-at type="dateTime">2016-10-24T21:41:51+06:00</created-at>
       <updated-at type="dateTime">2016-10-24T21:41:52+06:00</updated-at>
    <number type="integer">19</number>
    </order>

Solution

  • You can Either use XPATH or dataweave to do so.

    Xpath :-

    #[xpath3('/*:order/*:id',payload,"STIRNG")]

    OR Dataweave:-

    <dw:transform-message doc:name="Transform Message">
        <dw:input-payload mimeType="application/xml"/>
        <dw:set-variable variableName="variableName"><![CDATA[%dw 1.0
    %output application/java
    ---
    payload.order.id]]>
        </dw:set-variable>
    </dw:transform-message> 
    

    Hope this helps.