doing xml replace operations in logic apps - azure-logic-apps

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!

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.

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

Related

How to keep square brackets in single array using Logic Apps?

I am parsing an XML document to JSON, and eventhough I have the type array declared in the json schema, if there is just one element in the array it gets transformed into an objet like this.
"ListOfCodes":{"Codes":{{"Code":"111"}}}
but I need this:
"ListOfCodes":{"Codes":[{"Code":"111"}]}
I have several arrays in the document and I only get the sqare brackets when there is a multiple array.
and adding the properties manually is not an option.
Anyone know what can i modify to fix this in the logic app?
Unfortunately, there isn't a good solution for us to implement this requirement in logic app. Here is another post which is similar to your problem. To implement the requirement, we can just:
1. Use the "Compose" action to generate the object by hand (manually put all the properties and arrays where they need, potentially using the #array() action.
2. Call an Azure Function or some external code that can more specifically craft a valid JSON.
I also try to test it in some other way, such as use json:Array="true" and use <?xml-multiple?> but they all fail in logic app. So I think the only above two solutions(mentioned in that post) can be used. Neither approach is good, though.

Define multiple variable of same datatype in Azure Logic Apps

I am creating a Azure Logic App. I need to Define multiple variable of same datatype. What is the quickest / good way to define it. I tried code view to add more variables but seems its not supported yet:
What is the purpose of all the variables except for the obvious to store the data? My question is. Is it possible to parse the data into dynamic content by a Parse JSON action which a schema to store them as dynamic content with type string?
Otherwise, you will have to add multiple Initialize Variable actions after each other.
You could also store the data in a Variable array and work with it from there. Store it in an array and if you prefer Javascript inline Code

How to separate text values from string in JSON payload

Could someone point me in the right direction please?
I am trying to extract specific text/numbers from a json payload. I can access/isolate the full string of text by using triggerFormDataValue('text').
The text in question may contain 'sendSMS 1122334455 actual message' as its actual value
Is there anyway, in a logic app flow, to break the text into its component parts?
(sendsms, 1122334455 and actual message)
n.b. I have already tried interacting with the cognitive analysis app for key word searches but that doesn't return the number, nor the full sting, just the key words.
thanks
For more complex logic like the one you have, I would recommend to create an Azure Function. This is a light-weight solution that will offer you the flexibility of a microservice which offers you this possibility.
To extract the numbers, you may use a regular expression.
Edit:
I've found a similar question here on SO, but the conclusion is very similar.
I've done some small research now and it seems Microsoft deliberately does't put too much text parsing functionality in Logic Apps in order to avoid them being too complex. You might have a chance if you put them in JSON notation, but I think the better option would be to go to Azure functions, since it provides reuseability as well.
If that's all you need to do, you can use the split() function. Details: String Functions...split

Initialize entire drive realtime model from string?

I want to serialize all of the data in my realtime document to a string with which I can later initialize a new realtime document. I want to do this so my users can make copies of their drive files, save different versions, etc, and I can re-initialize the relevant realtime documents from the string.
I see I can call document.getModel().getRoot().toString() to get a string representation of the root CollaborativeMap, but I don't see any easy way to load that string back IN to a CollaborativeMap. Also, the string returned is not JSON, so I can't easily use JSON.parse to turn it back into a normal JS object and iterate from there.
I can make this work by hand. Is there any easy automated way?
You can do that on the service side using the realtime.get() and update() methods:
https://developers.google.com/drive/v2/reference/realtime

Why choosing for an Object Parser instead of an Array Parser

I'm parsing a XML-file into objects but I'm wondering why,
I would haven't choosed an Array Parser instead of an Object Parser?
Does it have more pro's than an Array parser or less contra's?
is it more flexible and expansible?
Kind regards
I think it all depends on the input data. If you application needs a lot of simple configuration files storing the state/setup of a single object, then there would be less overhead in handling the parser's output if you use ObjectParser.
But once you have a scenario when you need to store actual object collections (e.g., a list of independent GUI controls to be attached somewhere) and you read such collections often enough, then, if you still use ObjectParser you would have to invent a "collection" class and convert this list to the actual array.

Resources