Azure logic apps for xml data validation and transformation

Akshay Shinde </>
4 min readOct 12, 2022

Azure logic app provides in-built functionality to parse JSON payload based on provided schema (Actions → Data operations → Parse JSON) but no such in-built provision for XML payload parsing/validation.

In this post, I will show you how to setup simple Azure logic apps for xml data validation and transformation.

Business request is as below:

“Validate incoming XML request payload for data types and if valid as per schema then transform it into required business format XML.”

Sample XML data used for this tutorial as below:

Incoming XML request message :

<customerinfo>
<FirstName>Harry</FirstName>
<LastName>Potter</LastName>
<Phone>123</Phone>
</customerinfo>

Transformed XML response:

<?xml version=”1.0" encoding=”utf-8"?>
<Details>
<Name>Harry Potter</Name>
<PhoneNumber>123</PhoneNumber>
</Details>

After completing this tutorial, you will know:

1) Validate XML in azure logic app using schema.

2) Transform XML in azure logic app using map/stylesheet.

So, Lets get started! 🙂

Considering you are aware about basic process to create new workflow under standard-type logic app e.g. Logic app name : la-standard-xml-tranform.

While creation of new workflow, you can choose either state type : ‘Stateful’ or ‘Stateless’ based on business requirement.

Microsoft documentation has differentiated two workflow state type as below:
1) Stateful: Optimized for high reliability, ideal for process business transitional data.
2) Stateless: Optimized for low latency, ideal for request-response and processing IoT events.

step 1) Once new workflow has been added e.g. workflow name: xml-validate-transform , go to workflow designer view and add HTTP trigger ‘When a HTTP request is received’
Connector: Request

After this step, save your logic app.

step 2) Next part is to add business requested XML schema for validation.

As per input XML, I have created one XML Schema Definition or XSD named customerinfo.xsd and attached same xsd over here.

XSD : customerinfo.xsd

We need to add this xsd file in our logic app scope as below.

Go to our logic app → Artifacts → Schemas → Add Schema → Select schema → (You can use customerinfo.xsd)

step 3) Also regarding requested transformation I have added stylesheet named transform.xslt and attached same stylesheet over here.

stylesheet : transform.xslt

You can also use online XSLT Code Generator to generate stylesheet as per your need. We need to add this stylesheet file in our logic app scope.

So go to our logic app → Artifacts → Maps → Add Map → Select Map → (You can use transform.xslt)

step 4) Now, we need to add action where we can attach business required XML schema for validation.

Go to your logic app workflow designer → add action ‘XML Operations’ → Actions → ‘XML Validation’ → select schema that we can added i.e. ‘customerinfo’ and under content you can set @{triggerBody()} or select ‘Body’ output from previous node ‘When a HTTP request is received’

step 5) Next step is to add
‘XML Operations’ → Actions → ‘Transform XML’ and select stylesheet/map that we can added i.e. transform and under content you can set @{triggerBody()} or select ‘Body’ output from first node ‘When a HTTP request is received’

step 6) To send response we need to add action ‘Response’ (Request) and set body as output of ‘Transform XML’ i.e. @{body(‘Transform_XML’)}

Our final logic app workflow design will look like below:

For your reference, I have also attached code for above workflow design as below :

Logic app workflow code

Now, Lets test this logic app exposed endpoint (method-post) in postman with two test cases:

  1. Invalid data type request :

<customerinfo>

<FirstName>Harry</FirstName>

<LastName>Potter</LastName>

<Phone>abcd</Phone>

</customerinfo>

Above request is getting failed as expected ! Cool 😎

You can track this validation error in logic app workflow run history under action ‘XML Validation’. We can see it got errored out due to invalid data received for ‘Phone’

2. Valid data type request :

Lets post below valid XML data and hit send on postman !

<customerinfo>

<FirstName>Harry</FirstName>

<LastName>Potter</LastName>

<Phone>123</Phone>

</customerinfo>

We can observe that request data has been successfully passed through both actions i.e. XML Validation and Transform_XML .We can see below expected response XML 🙂 :

<?xml version=”1.0" encoding=”utf-8"?>

<Details>

<Name>Harry Potter</Name>

<PhoneNumber>123</PhoneNumber>

</Details>

Thanks for reading my article till end. Stay tuned and follow me for more updates. Don’t forget to give is your 👏 if you really enjoyed reading this article just to support your author also please share to your friends..! 🙂

Thanks - Akshay Shinde

--

--