object:
<Result>
<Test>
<Value>First</Value>
</Test>
</Result>
object2:
<Result>
<Test>
<Value>Second</Value>
</Test>
</Result>
Combination of 2 objects, We can use the first object and just add the attribute of the object2 to it. The Desired output should look like this:
<Result>
<Test>
<Value>First</Value>
<Value>Second</Value>
</Test>
</Result>
CodePudding user response:
Those are not really objects in DataWeave. They are strings that contain an XML document. They may be in the payload and variables with the correct content type and DataWeave will parse automatically into objects. To simplify the example I will parse them manually in my script.
In this solution I will take the value of Result.Test from both objects, in this case a collection of key-values, and concatenate them together.
%dw 2.0
output application/xml
import mergeWith from dw::core::Objects
var in1=read("<Result>
<Test>
<Value>First</Value>
</Test>
</Result>", "application/xml")
var in2=read("<Result>
<Test>
<Value>Second</Value>
</Test>
</Result>", "application/xml")
---
{
Result: {
Test: in1.Result.Test in2.Result.Test
}
}
Output:
<?xml version='1.0' encoding='UTF-8'?>
<Result>
<Test>
<Value>First</Value>
<Value>Second</Value>
</Test>
</Result>