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:
The For each takes the XPath query as a parameter, from which it runs the debatch.
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 more information on for each: For each loops.
The splitOn parameter, which can only be used in code view, is used to debatch in an HTTP trigger.
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.
For a call to the LA_debatch_with_trigger Logic App, three instances of the Logic App are triggered.
Each instance of the Logic App contains one record which has been debatched.
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.