Forum Discussion

tadudek's avatar
tadudek
Occasional Contributor
5 years ago

How to map repeating elements from xml response to datasink

I've been scouring the doc, and I can't seem to find a good answer here. 

 

Is there a way to map a repeating element from a response into a datasink automatically, rather than having to click getData and manually clicking each one?

 

So, if I have 25 repeating elements. Widgets again. They all have the same attributes. A1, A2, A3. I want my sink to collect each of the attributes from each of the widgets, but I don't want to have to map it explicitly in the data sink property and the every one of the 25 widgets (x3 attributes) in my response.

 

example: 

<widgets>
    <widget>
         <att1>abc</att1>
         <att2>xyz</att2>
         <att3>asd</att3>
     </widget>
    <widget>
         <att1>abc</att1>
         <att2>xyz</att2>
         <att3>asd</att3>
     </widget>
...
</widgets>

 

In my datasink, I'd like to map these out 1 element to 1 row in excel: 

excel row 1 (first widget): att1: abc, att2: xyz, att1: asd 

excel row 2 (second widget): att2: abc, att2: xyz, att1: asd 

 

Is there a way to do that? 

  • nmrao's avatar
    nmrao
    Champion Level 3
    Never tried/used data sink.

    It is understand there is some customization.
    But how it is working with default behaviour when you tried?
    • tadudek's avatar
      tadudek
      Occasional Contributor

      It's currently just pulling the first widget. Because you have to click, get data, and point to the first widget's attributes to map it to the column in excel. It seems that it'd be a common use case to have repeating elements. I did import a schema for the response, and with the schema, it would know that there are repeats. 

       

      I'm guessing I need to write custom groovy to do it.

      • nmrao's avatar
        nmrao
        Champion Level 3
        You are correct by saying that it is common to have repeated elements in the GET response. However, some are ok with default behaviour and you wanted it probably different.
        You can write script in what ever way you wanted.