felixmondelo
felixmondelo

Reputation: 1474

Logic Apps Liquid connector – transform XML

With Liquid maps we can transform a simple XML to a JSON, for example this XML:

<root>
   <product>
      <name>TV</name>
      <price>499.9</price>
   </product>
</root>

We can apply this Liquid map and get a valid JSON:

{
   "name": "{{content.product.name}}",
   "price": {{content.product.price}},
}

How can implement the same map, if my source XML has namespaces, for example:

<ns0:root xmlns:ns0="http://customnamespace.com" xmlns:ns1="http://customnamespace2.com">
   <ns1:product>
      <ns1:name>TV</ns1:name>
      <ns1:price>499.9</ns1:price>
   </ns1:product>
</ns0:root>

Upvotes: 1

Views: 1394

Answers (1)

felixmondelo
felixmondelo

Reputation: 1474

The solution is transform the XML to JSON and use bracket notation in our Liquid map:

{    
    "First" : "{{ content['ns0:X12_00401_850'].ST.ST01 }}"
}

For an inputs XML transformed to JSON as this:

{
  "content": {
    "ns0:X12_00401_850": {
      "@xmlns:ns0": "http://schemas.microsoft.com/BizTalk/EDI/X12/2006",
      "ST": {
        "ST01": "850",
        "ST02": "476810004"
      },

Upvotes: 1

Related Questions