2
votes

Input XML:

 <Orders>
 <Order>
   <sample id="a">23435</sample>
   .
   .
   .
  <sample id="x">D123</sample>
     .
      .
  <sample id="y">5346</sample>
  <sample id="z"></sample>
  .
  .
  </Order>
 <Order>
   <sample id="a">23435</sample>
   .
   .
   .
  <sample id="x">D345</sample>
     .
      .
  <sample id="y">5346</sample>
  <sample id="z">D217</sample>
  .
  .
  </Order>
 <Order>
   <sample id="a">23435</sample>
   .
   .
   .
  <sample id="x">D1235</sample>
     .
      .
  <sample id="y">5346</sample>
  <sample id="z"></sample>
  .
  .
  </Order>

Requirement:

If 'sample' element with attribute='z' has no value then I need to map 'sample' element with attribute 'x' to 'ProId'; else if it has value, then I should not pass any value to 'ProFeed' map. (For each 'Order' element I need to create one 'ProFeed' map)

Output:

 [ProFeed={ProId="",Lang="eng",CatId="AU"},ProFeed={ProId="",Lang="eng",CatId="AU"},ProFeed={ProId="",Lang="eng",CatId="AU"}]

DataWeave config:

%input application/xml 
%output application/java
.(some configuration code)
.
.

Please help me out in the configuration of DataWeave component.

2
Please do comment incase you need any clarification in the requirement. I am very new to dataweave.masetti mani kanta
Can I use this in the configuration instead? %input application/xml %output application/jsonRalph Rimorin
@RalphRimorin Please post your configuration, I can verify if it works.masetti mani kanta
Please answer this as it is one of important requirement for memasetti mani kanta
Are you still there? Sorry I didn't rreply.Ralph Rimorin

2 Answers

3
votes

You can try enhancing this:

enter image description here

The only problem here is otherwise $, which should able to return the value of the sample with attribute "x". I can't figure how to nested the when/otherwise

0
votes

The below should be your logic . Fill it for your scenario

%dw 1.0
%output application/json
---

payload.Orders map {
  ProId: $.id when $.@id != null otherwise $.sample,
  .....
}