Transform XML in a Logic App

Transform XML in a Logic App


If you are integrating two systems through XML where none of the systems conform to the other we have to make the receiving system able to read the data. In this example we will transform XML from one schema to another.

Get XSD files of your XML files

If you have XSD files for your from and to XML structures, you can skip this step. Below are two sets of XML structures, they actually matches but they have different language. This for the simplicity of the example. 

Generate XSD for each of the XML structures, this can be done here:  https://www.freeformatter.com/xsd-generator.html#ad-output

Fom XML:

<?xml version="1.0" encoding="utf-8"?>
<products>
<product>
<itemId>ABC123</itemId>
<itemName>ABC 123</itemName>
<price>1</price>
<unit>pcs</unit>
</product>
</products>

To XML: 

<?xml version="1.0" encoding="utf-8"?>
<varer>
  <vare>
    <vareNummer>ABC123</vareNummer>
    <vareNavn>ABC 123</vareNavn>
    <pris>1</pris>
    <enhet>pcs</enhet>
  </vare>
</varer>

  1. Get your from XSD and save it to a file with the extension .xsd.
  2. Get your to XSD and save it with the extension .xsd.


Create a Map (Visual Biz talk XSLT)

Map in this instance is a visual BizTalk XML Stylesheet Language Transform. 

  1. Create a Integration account project in Visual Studio

  2. Add your to and from XSD files to the project
  3. Add a new item of type Map


  4. Double click the map you just created
    1. In the from section add the from XSD
    2. In the to section add the to XSD
    3. drag and drop the mappings in the fields

  5. When done build the project to produce the XSLT file, located in bin/debug/ folder.

Create an Integration account

Go to your Azure portal and create an Integration account. 
  1. Same resource group and location as your logic app and wait for it to deploy
  2. Open the resource and choose maps from the left most menu under Settings
    1. Upload your XSLT file
  3. Choose the Schemas menu option from the left
    1. Upload your XSD to schema, the resulting XML structure.


Create a logic app transforming XML

For simplicity sake, this will be a hardcoded logic app with XML hardcoded into it.


  1. Create a new logic app
    1. Same resource group and location as your integration account
  2. Go to Settings --> Workflow settings
    1. Specify the integration account you just added



  3. Add whichever trigger you want to start
  4. Add XML transform Action
    1. Add your from XML in the Content field
    2. Choose your Map (from the Integration Account your just created)
  5. Add XML validation action
    1. Content: "Transformed XML"
    2. Schema name: your to XSD you uploaded to the integration account
  6. Run your logic app to see the results.




In my example I entered this XML structure:


<?xml version="1.0" encoding="utf-8"?>
<products>
<product>
<itemId>ABC123</itemId>
<itemName>ABC 123</itemName>
<price>1</price>
<unit>pcs</unit>
</product>
<product>
<itemId>DEF123</itemId>
<itemName>DEF 123</itemName>
<price>2</price>
<unit>pcs</unit>
</product>
<product>
<itemId>GHI123</itemId>
<itemName>GHI 123</itemName>
<price>3</price>
<unit>pcs</unit>
</product>
<product>
<itemId>JKL123</itemId>
<itemName>JKL 123</itemName>
<price>4</price>
<unit>ltr</unit>
</product>
</products>


The logic app transformed the XML to this:


<?xml version="1.0" encoding="utf-8"?>
<varer>
  <vare>
    <vareNummer>ABC123</vareNummer>
    <vareNavn>ABC 123</vareNavn>
    <pris>1</pris>
    <enhet>pcs</enhet>
  </vare>
  <vare>
    <vareNummer>DEF123</vareNummer>
    <vareNavn>DEF 123</vareNavn>
    <pris>2</pris>
    <enhet>pcs</enhet>
  </vare>
  <vare>
    <vareNummer>GHI123</vareNummer>
    <vareNavn>GHI 123</vareNavn>
    <pris>3</pris>
    <enhet>pcs</enhet>
  </vare>
  <vare>
    <vareNummer>JKL123</vareNummer>
    <vareNavn>JKL 123</vareNavn>
    <pris>4</pris>
    <enhet>ltr</enhet>
  </vare>
</varer>

Comments

Popular posts from this blog

Call a simple Logic app from X++

SysOperationFramework with use of Query

Retail Attributes on sales lines