1
votes

We have a scenario where we need to concatenate all XML node values to String.

input XML

<root>
  <line>1</line>
  <line>2</line>
  <line>3</line>
  <line>4</line>
</root>

Output to String

1234

Please let me know how can i achieve in form of String.

Thanks in advance.

2

2 Answers

0
votes

Referring DataWeave Reference Documentation at Reduce section:

Transform

%dw 1.0
%output application/json
---
concat: ["a", "b", "c", "d"] reduce ($$ ++ $)

Output

{
  "concat": "abcd"
}

Therefore, you can try something like this: concat: payload.root.*line reduce ($$ ++ $)

0
votes

Try with this:

%dw 2.0
output application/json
---
{
    result: payload.root.*line reduce ((item ,acc="") -> acc ++ item)
}