Search code examples
dataweavemule4

how to get the type value from xml in Mule 4


<?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>
    <Notification>
      <Id>4535etrete</Id>
      <sObject xsi:type="sf:val" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
      <sf:Programs>F Type A</sf:Programs>
</sObject>

I want to get the value of <sOject> type ie sa:val


Solution

  • First of all your xml is not valid. I modified it to the following to provide you a sample.

    <?xml version="1.0" encoding="UTF-8"?>
        <order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <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>
        <Notification>
          <Id>4535etrete</Id>
          <sObject xsi:type="sf:val" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
          <sf:Programs>F Type A</sf:Programs>
         </sObject>
        </Notification>
      </order>
    

    The DW script to procure the attribute 'type' from sObject will be as follows:

    %dw 2.0
    output application/json
    ---
    payload.order.Notification.sObject.@'type'