5

How do we replace strings within an XML payload in logic apps?

input

<root>
  <alexIsAwesome>yes he is</alexIsAwesome>
  <bytes>sdfsdfjijOIJOISJDFQPWORPJkjsdlfkjlksdf==</bytes>
  <bytes>SFSDFsdfsdgfjgjkfjsdlfkjlksdf==</bytes>
</root>

desired result

<root>
  <alexIsAwesome>yes he is</alexIsAwesome>
  <bytes>replacetext1</bytes>
  <bytes>replacetext2</bytes>
</root>

How do we iterate through XML and replace text within nodes? Please keep in mind that the input node might be 100mb in size!

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

2 Answers2

3

If you already loading the XML content in you Logic App, you could just use the replace function. Note that there are certain limits that you may end up hitting on successive runs.

If you have more complex use cases, you could instead try one of the following

For payloads up to 50MB, you could simply use the new inline code feature to perform the transformations you need. You would have to convert the payload to JSON first (using json) and then back to XML after (using xml).

But for much bigger payloads and/or more complex transformations, it would be best to offload this to a Function called from Logic App.

The best approach here would be to store the payload in Azure Blob Storage and your function would have a Blob Input and Blob Output binding.

PramodValavala
  • 6,026
  • 1
  • 11
  • 30
3

You could use an Integration account with the Transform XML action, by pointing to a defined Map, either XSLT or Liquid type. logic apps enterprise integration maps

AdAstra
  • 1,934
  • 11
  • 9
  • 1
    would love to see an example of `liquid type` – Alex Gordon May 28 '19 at 14:02
  • 1
    @l--''''''---------'''''''''''' Sorry, I have not tried but it yet, I plan to use it myself in an upcoming project. Here is the link to the Azure documentation, the examples look fairly straight forward: https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-enterprise-integration-liquid-transform – AdAstra May 28 '19 at 15:54