Debatching XML message in Logic App

Camille Schneider
Published by Camille
Category : Azure / Logic apps
30/12/2019

The following shows two methods that can be used to debatch an XML message in a Logic App. The first consists in making an XPath query in a For each. The second, which also needs an XPath query, is carried out using an HTTP trigger.

Here is the sample message used:

Orders message

 

Method 1: For each

The For each takes the XPath query as a parameter, from which it runs the debatch.

Logic App For each

XPath query:

xpath(variables('xml'), '/*[local-name()="Orders" and namespace-uri()="http://Article_debatching.Orders"]/*[local-name()="OrderLine"]')

 

On executing the For each, the message has been split into three parts, which matches the number of For each iterations.

For each result

For more information on for each: For each loops.

 

Method 2: Logic App HTTP Triggers

The splitOn parameter, which can only be used in code view, is used to debatch in an HTTP trigger.

splitOn parameter

The XPath query is made in the splitOn parameter:

@xpath(xml(triggerBody()), '/*[local-name()=\"Orders\" and namespace-uri()=\"http://Article_debatching.Orders\"]/*[local-name()=\"OrderLine\"]')

 

To proceed with the debatch, the Logic App is called from another, being the one containing the entire message.

Debatch from another Logic App

 

For a call to the LA_debatch_with_trigger Logic App, three instances of the Logic App are triggered.

Debatch result

 

Each instance of the Logic App contains one record which has been debatched.

Debatch result 2

Conclusion

Both solutions are effective in debatching XML in a Logic App. If the processing for each node needs to be independent from the others, the splitOn parameter is the more elegant solution. Conversely, For each loops make it possible to stop debatching if there is an error in any of the processing.