nerdexam
MuleSoft

MCD-LEVEL-1 · Question #180

Refer to the exhibits. What DataWeave expression transforms the conductorIds array to the XML output? A. 1. 1. trains: 2. 2. conductorIds map ((engId, index) -> 4. 4. engineerId: engId 5. 5. } 6. 6…

The correct answer is C. 1. trains: 2. {( 3. conductorIds map ((engId, index) -> 4. train: { 5. engineerId: engId 6. } 7. ) 8. )}. Points to remember: XML must have a root element. XML only allows one root element To avoid multiple root issues, you must create a root element for the XML output, whenever we transform output When mapping array elements (JSON or JAVA) to XML, wrap the map operations in {(..)}…

Use DataWeave to transform data

Question

Refer to the exhibits. What DataWeave expression transforms the conductorIds array to the XML output? A. 1. 1. trains: 2. 2. conductorIds map ((engId, index) -> 4. 4. engineerId: engId 5. 5. } 6. 6. ) B. 1. 1. { trains: 2. 2. 3. 3. conductorIds map ((engId, index) -> 4. 4. train: { 5. 5. engineerId: engId 6. 6. } 7. 7. ) 8. 8. } C. 1. 1. trains: 2. 2. {( 3. 3. conductorIds map ((engId, index) -> 4. 4. train: { 5. 5. engineerId: engId 6. 6. } 7. 7. ) 8. 8. )} D. 1. 1. {( trains: 2. 2. 3. 3. conductorIds map ((engId, index) -> 4. 4. train: { 5. 5. engineerId: engId 6. 6. } 7. 7. ) 8. 8. )}

Exhibit

MCD-LEVEL-1 question #180 exhibit

Options

  • A
    1. trains:
    2. conductorIds map ((engId, index) ->
    3. train: {
    4. engineerId: engId
    5. }
    6. )
  • B
    1. { trains:
    2. conductorIds map ((engId, index) ->
    3. train: {
    4. engineerId: engId
    5. }
    6. )
    7. }
  • C
    1. trains:
    2. {(
    3. conductorIds map ((engId, index) ->
    4. train: {
    5. engineerId: engId
    6. }
    7. )
    8. )}
  • D
    1. {( trains:
    2. conductorIds map ((engId, index) ->
    3. train: {
    4. engineerId: engId
    5. }
    6. )
    7. )}

How the community answered

(26 responses)
  • A
    23% (6)
  • B
    8% (2)
  • C
    58% (15)
  • D
    12% (3)

Explanation

Points to remember: * XML must have a root element. * XML only allows one root element * To avoid multiple root issues, you must create a root element for the XML output, whenever we transform output * 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 * The transformation to XML would fail if the above mentioned considerations were not taken into * Thus the transformation script declares a root element as trains and wraps the data in "{( )}". Whenever you see such type of question, always look out for root element followed by {( )} wrapping I call this a "Wrap The Map" scenario. Hope it would help you remember !

Topics

#DataWeave#XML output#map function#array to XML

Community Discussion

No community discussion yet for this question.

Full MCD-LEVEL-1 Practice