Wednesday, May 16, 2018

Parse XML using Microsoft Flow

* For any help in Nintex & MS Flow drop a comment.

Here I will take sample xml and try to parse it using Microsoft flow. Below is the screenshot of full flow.

  1. In this flow I am adding button as flow trigger however you can add this logic in your flow under any trigger.
  2. Next , I added compose action (renamed to XML Data) and added the sample XML as shown below.
        Sample XML
       <?xml version="1.0"?>
               <Country type="System.String">ABC</Country>
<Country type="System.String">XYZ</Country >

      3. Add one more compose action(renamed to Use xpath) where we will use xpath to get the xml nodes as shown below.
           Formula used in this compose action:
  • In xpath expression, first parameter asks for xml data. So we used xml() action to convert our data into valid xml form.
  • Second parameter asks for expression to specify which node to read.
  • //Country means it will parse xml and get all the “<Country>” nodes irrespective of it’s location.
  • Output of step 3 would be array of  
  • "<Country type="System.String">India</Country>" and "<Country type="System.String">Japan</Country>" 

     4. Since we have multiple “<Country>” nodes, so output will be an array. 
     5. To read array use “Apply to Each” action and add the output of xpath action from previous action as parameter as shown below.

     6. Insert a compose action renamed as (Get Current Node Text) inside apply to each              loop to read the current node of array as shown above.
     7. Use this xpath expression to get current node as text.
     8. Now run the flow you will get Countries as text as shown below.

No comments:

Post a Comment