What DataWeave expression transforms the array a to the XML output?
A.
1.
1. trains:
2.
2. {(
3.
3. a map ((engId, index) ->
4.
4. train: {
5.
5. TrainNumber: engId
6.
6.
7.
7. }
8.
8. )
9.
9. )}
B.
1.
1. trains:
2.
2. a map ((engId, index) ->
3.
3. train: {
4.
4. TrainNumber: engId
5.
5.
6.
6. }
7.
7. )
C.
1.
1. {(
2.
2. trains:
3.
3. a map ((engId, index) ->
4.
4. train: {
5.
5. TrainNumber: engId
6.
6.
7.
7. }
8.
8. )
9.
)}
D.
1.
1. {
2.
2. trains:
3.
3. a map ((engId, index) ->
4.
4. train: {
5.
5. TrainNumber: engId
6.
6.
7.
7. }
8.
8. )
9.
}
A
Explanation:
For such questions always look for Syntax:
I call it "Wrap the Map"
trains:
{(
When mapping array elements (JSON or JAVA) to XML, wrap the map operations in {(..)}
-{ } are defining the object
-( ) are transforming each element in the array as a key/value pair
Given answer is wrong. Check the official documentation: https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-map
The map is NOT wrapped. So the correct answer is B.
look, I tested on the application, your answer gives me an error while with A it gives me the correct result as in the image so I think the right answer is A