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"?>
       <Countries>
               <Country type="System.String">ABC</Country>
<Country type="System.String">XYZ</Country >
         </Countries>



      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:
           xpath(xml(outputs('XML_Data')),'//Country')
   
  • 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.
         xpath(xml(item()),'string(.)')
     8. Now run the flow you will get Countries as text as shown below.



3 comments:

  1. I reached this page as the end of trying to parse an XML API from PowerApps. It seems I still need to connect all the pieces to actually accomplish this task. We need an E2E example from creating the connector to consuming the resulting fields in an app

    ReplyDelete
    Replies
    1. If I understand what your saying. I would try to put your XML results from THIS example into an array and then push that array into powerapps as a collection when the app loads. check out this video. I used this to bring in and combine data from an api and an on premise sql database that could be displayed in a gallery.

      https://powerusers.microsoft.com/t5/Webinars-and-Video-Gallery/Return-an-Array-from-Flow-to-PowerApps-Split-Method/td-p/113061

      It takes a bit of time to figure it all out, but it does work quite well.

      Delete
  2. can you suggest me how to send data in html table from xml data ?






    purushottam
    08/19/2020 00:00:00
    IT


    Mahi
    08/28/2020 00:00:00
    Sales


    ReplyDelete