Unable to parse xml for rich text editor in InfoPath form using PowerAutomate

210 Views Asked by At

I want to fetch all the text inside below tag using PowerAutomate expression, How can i achieve that? Right now i am trying with below xpath expression but it is nor returning readable result.

xpath(xml(outputs('Compose_3')),'//purpose')



 <purpose>
    <div xmlns="http://www.w3.org/1999/xhtml">Action due to regulatory compliance.</div>
    <div xmlns="http://www.w3.org/1999/xhtml"> </div>
    <div xmlns="http://www.w3.org/1999/xhtml">These corrective action are required by European Guideline 94/9/EG, 1999/92/EG (ATEX) and their implementation in German law BetrSichV and TRBS.</div>
    <div xmlns="http://www.w3.org/1999/xhtml">Based on Risk analysis (Explosion protection </div>
 </purpose>
1

There are 1 best solutions below

3
Skin On

Firstly, what you've done is obtained the values within but it's encoded as base64, you can avoid that though. Therefore, I've got two approaches for you.

All Text Extract

This is the flow ...

Flow 1

Initialize XML

This is merely your XML in a string variable so I can get the answer you need.

Initialize Inner Text

This expression will give you all of the inner text contained within the purpose element.

xpath(xml(variables('XML')), 'string(//purpose)')

This is the result ...

Result 1

Array of Texts

This is the more complicated approach but what it does is split out the text strings into an array variable so you're able to control it better if need be.

This is the flow ...

Flow 2

Initialize XML

This is merely your XML in a string variable so I can get the answer you need.

Initialize Purpose Children

This is an xml/xpath expression to get an array of all div elements within the purpose element.

Initialize Purpose Children

The expression with that step is ...

xpath(xml(variables('XML')), '//*[local-name()="div"]')

Initialize Inner Text Array

This is just a blank array that will be populated within the subsequent Apply to Each.

Apply To Each (Purpose Elements)

You want to loop through all of the items within the Purpose Children array.

Apply To Each

The only action occurring within there is to append to the Inner Text Array variable.

The expression within that step is ...

xpath(xml(concat('<xml>', base64ToString(item()?['$content']), '</xml>')), 'string(//*[local-name()="div"])')

This is the end result ...

Result 2

This approach also allows you to concatenate the strings together to produce a more legitimate paragraph of text.