How to extract information from XML/HTML/FSON and convert it into PlainText in Canvas PowerApps without Flow

Posted On March 16, 2021 by Ethan Rebello Posted in  Tagged in , ,

If you are curious about the data in XML/HTML/JSON and want to fetch data from it without flow. Here’s something what you can do

There’s an inbuilt function in PowerApps that converts HTML/XML to string text.
Function Name is ‘PlainText‘. But all tags are neglected and extracting certain data is difficult.

Consider you want to extract a small size information which is in XML/HTML/JSON and don’t have time to write a flow.

Here’s what you can do

I have a XML data.
Tip: When converting your XML/HTML to PlainText. It’ll show space and next line if you place tags correctly. Keeping in 1 line or no spaces will reflect in result which will look bad.

<employee><firstName>John</firstName> <lastName>Doe</lastName></employee>
<employee><firstName>Anna</firstName> <lastName>Smith</lastName></employee>
<employee><firstName>Peter</firstName> <lastName>Jones</lastName></employee>
<employee><firstName>Jack</firstName> <lastName>Sparrow</lastName></employee>
<employee><firstName>Barry</firstName> <lastName>Allen</lastName></employee>
<employee><firstName>Jonas</firstName> <lastName>Wood</lastName></employee>
<employee><firstName>Max</firstName> <lastName>Payne</lastName></employee>

I have created 2 buttons and 2 input text boxes.

  • 1st button will set XML/HTML/JSON in a variable or collection
  • 2nd button will check for next values if tag found.
  • 1st and 2nd input Text Boxes represent start and end tags

There are 3 main variables that we’ll use to iterate the values.

UpdateContext({Current: Find(TagFind.Text, var1, Next)});
UpdateContext({CurrentEnd: Find(TagFind_End.Text, var1, Current)});
UpdateContext({Next: Current+1});

Here TagFind, TagFind_End are 2 input text boxes and var1 is variable holding XML data.

Find function finds data which is encountered once. Since it has starting point we define it to iterate to next search.

Current and CurrentEnd will represent start and end point of tag.
Next will determine next index to start searching from

We will have 1 label to show our answer

"Your Result : " &Mid(var1, Current + Len(TagFind.Text), CurrentEnd-(Current + Len(TagFind.Text)))

Here the text property has the formula that retrieves data within the start and end point of the tag.

Finally you will achieve something like this,

You can use this fetched data somewhere in your PowerApp.

You can also use something similar to extract values in branched data form. In a certain range of data.
For example; In above XML, i have ’employees’ as 1 tag determining contents in it.
If i had Name tag in employees and Name tag in ‘Department’ then by range of ‘Employees’ or ‘Department’ i can fetch Name of that block only.

Hope this idea helped.

Share Story :