Search code examples
muledatamappermule-studiomule-elmule-component

Mule ESB: How to use rules in DataMapper for condition checking


Please help me. I'm using datamapper to convert xml to csv. PF my xml below. If ID = 1, then i need to map schoolRating , and also ID=2 then need to map schoolRating with other filed in csv. Though this xml i created schema.

<root>
  <schoolTypes>
    <ID>1</ID>
     <Record>
       <SchoolRating>4.0</SchoolRating>
       <Tables>67</Tables>
     </Record>
  </schoolTypes>
  <schoolTypes>
   <ID>2</ID>
     <Record>
       <SchoolRating>3.0</SchoolRating>
        <Tables>67</Tables>
     </Record>
   </schoolTypes>
 </root>

i have tried to create rules like this in DataMapper, but it throws error.

     Context:  /ns0:root
     Xpath:    /ns0:schoolTypes/@(ns0:ID='1')/ns0:Record/ns0:SchoolRating

Also tried with multiple options but no hope. Please let me know the right syntax for this condition or any other approach to handle this in DataMapper. Thanks in advance.


Solution

  • you should create the rule in DataMapper:

    Context:  /ns0:root
    Xpath:    /ns0:schoolTypes[ns0:ID='1']/ns0:Record/ns0:SchoolRating
    

    you may need to check this for more info.