# How to convert a message to XML data format

In this tutorial we will be converting a valid xml string in the message to javascript object.

  1. TDB Following is the input xml string which we will be using in this use case.

    <Records>
     <EmpName>Jack</EmpName>
     <EmpNo>1234</EmpNo>
     <Building>West</Building>
     <EmpName>Harry</EmpName>
     <EmpNo>1789</EmpNo>
     <Building>East</Building>
    </Records>
     
    
  2. Drag and drop set property node from the transformation section in the pallette. Double click the node to open the editor.

  3. Click Add button under rules and select Set. Configure the Set field value as msg.payload. Select String for the to field type and provide the following on value section of to field.

  <Records>
    <EmpName>Jack</EmpName>
    <EmpNo>1234</EmpNo>
    <Building>West</Building>
    <EmpName>Harry</EmpName>
    <EmpNo>1789</EmpNo>
    <Building>East</Building>
  </Records>
  1. Wire the TBD to set property node.

  2. Drop XML node from the transformation section to the canvas. Double click the xml node to open the editor.

  3. keep all the setting in JSON node as default.

  4. click Save.

  5. Wire the set property node to XML node.

  6. Drop the debug node to the end of the flow and name it as Completed. Double click and open the debug node editor and set the Output as msg.payload.Records.EmpName[1].

TIP

msg.payload.Records.EmpName[1] allows to access the address field from the object converted from json string

  1. Wire the xml node to debug node.

  2. Now click the TBD to test the flow.

Observation

On the debug panel on the final debug node (Completed) the following payload will be printed.

Harry