Share via

LogicApp xml function output format

junyan2000 1 Reputation point
2021-08-26T02:01:41.11+00:00

LogicApp comes with an xml function, which creates an xml string representation of a variable. My question is whether the xml string can be made to conform to a schema.

For example, Parse JSON action creates a variable based on JSON string, then xml(body('Parse_JSON')) generates an xml string. How to control namespace? How to specify fields as element or attribute?

As it is, an extra xslt is required just to put values in the right place.

Azure Logic Apps
Azure Logic Apps

An Azure service that automates the access and use of data across clouds without writing code.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,661 Reputation points Microsoft Employee Moderator
    2021-08-27T08:42:54.423+00:00

    @junyan2000 While there isn't a way to pass a schema to conform to, the xml function makes the conversions using the conversion rules followed by JSON.NET.

    So, if you were to require an XML Payload like this

       <?xml version='1.0' standalone='no'?>  
       <root>  
         <person id='1'>  
           <name>Alan</name>  
           <url>http://www.google.com</url>  
         </person>  
         <person id='2'>  
           <name>Louis</name>  
           <url>http://www.yahoo.com</url>  
         </person>  
       </root>  
    

    You could require to pass in JSON in the following format

       {  
         "?xml": {  
           "@version": "1.0",  
           "@standalone": "no"  
         },  
         "root": {  
           "person": [  
             {  
               "@id": "1",  
               "name": "Alan",  
               "url": "http://www.google.com"  
             },  
             {  
               "@id": "2",  
               "name": "Louis",  
               "url": "http://www.yahoo.com"  
             }  
           ]  
         }  
       }  
    

    Another option would be to leverage Liquid Templates to convert from JSON to XML.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.