0
votes

I have the following xml as my input

InputXML:

<Orders>
<Order>
  <sample id="1"></sample>
  <sample id="2"></sample>
  .
  .
  .
  .    
 </Order>
<Order>
  <sample id="1"></sample>
  <sample id="2"></sample>
  .
  .
  .
  .    
 </Order>
<Order>
   <sample id="1"></sample>
   <sample id="2"></sample>
   .
   .
   .
   .    
</Order>
.
.
.
.
</Orders>

I need to send this xml to the batch component in my flow. My batch should accept each record in the following manner

  Record1:1st Order
  Record2:2nd Order
  Record3:3rd Order
  .
  .
  .
  .

Now please let me know what coding do I need to do in my DataWeave(Transform message) component to acheive this scenario.I tried multiple ways but no result. I am trying this from past few days and got tired. Please help me in this regard!! Please share the sample code.

Output should look like:

1) Order  ---- Object
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .
2) Order  ---- Object
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .

Inside Batch:

I do have another dataweave component that transforms this collection to csv.

The input of this dataweave component is each object from this collection. The data is extracted from this object and written to the CSV file.

Updated Question:

The issue I am facing is Each Object in the collection is of structure

 Order  ---- Object
          sample1-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
          sample2-----Object
              -sampleValue(i.e; value of 'sample' element)
              -sampleidValue(i.e; value of attribute of 'sample')
            .
            .
            .
            .

But the output of my CSV should be:

        sample1.sampleValue   sample3.sampleValue   .    .       .       .(this is 'Order1' object)
            sample2.sampleValue   sample6.sampleValue   .    .       .       .(this is 'Order2' object)
.
.
.
.

I am not able to get the output this way in the CSV file. bcz my 'sample' is also a List of Objects. I tried this in both DataMapper and DataWeave also. Please help me out how to extract the values.

1
Please do comment incase of any clarification in the question. Thanks in advance!!!masetti mani kanta
Can you elaborate more on the output format.Explain with an exampleNaveen Raj
@NaveenRaj Hi, My output should look like:masetti mani kanta
@NaveenRaj I have a batch process in my flow. As, we know batch accepts only ArrayList of Objects(as records). So, I need to convert the Input XML to the CollectionMap. Each Object must have data like: ------------------------------------------masetti mani kanta
'Order ---- Object sample-----Object -sampleValue(i.e; value of 'sample' element) -sampleidValue(i.e; value of attribute of 'sample') sample-----Object -sampleValue(i.e; value of 'sample' element) -sampleidValue(i.e; value of attribute of 'sample') . . . Order ---- Object sample-----Object . . .'masetti mani kanta

1 Answers

0
votes

Hi Please find the below Data Weave

%dw 1.0
%output application/csv separator=" "
---

payload.Orders.*Order map {
SampleValue1:$.sample.@id,
SampleValue2:$.sample.@id,
SampleValue3:$.sample.@id   
}

The below is the X%dw 1.0

%output application/csv separator=" "

payload.Orders.*Order map {
SampleValue1:$.sample.@id,
SampleValue2:$.sample.@id,
SampleValue3:$.sample.@id   
}

The below is the xml that I have used based on the xml that is shared in the question.

<?xml version="1.0"?>
<Orders>
<Order>
  <sample id="1">test</sample>
</Order>
<Order>
  <sample id="1">test</sample>
</Order>
<Order>
   <sample id="1">test</sample>
</Order>
</Orders>

Hope this helps!