SteveC
SteveC

Reputation: 16823

Is there an equivalent to the ParseJson action for XML data?

In Logic Apps we have the ParseJson action, which gives the individual fields.

But what about an equivalent for parsing XML?

So for example, if I had an XML over HTTP web service, which received the XML body ...

<root>
  <person>
    <firstname>Paul</firstname>
    <lastname>Getty</lastname>
  </person>
  <person>
    <firstname>John</firstname>
    <lastname>Denver</lastname>
  </person>
</root>

How could I achieve a similar experience to the ParseJson action generating tokens for each of the XML elements (and attributes?)

Upvotes: 1

Views: 51

Answers (2)

Michał Szecel
Michał Szecel

Reputation: 1

You cannot do that directly.

What I am doing is I am parsing it indirectly through XML - just as @AdAstra mentioned.

  1. Generate json schema for your XML - You can use any online converter like for example https://codebeautify.org/xmltojson

    For your XML the Json will look like:

{
   "root": {
      "person": 
      [
         {
            "firstname": "Paul",
            "lastname": "Getty"
         },
         {
            "firstname": "John",
            "lastname": "Denver"
         }
      ]
   }
}

  1. Use Parse JSON Control with TriggerBody as a Content and generated schema pasted in 'Use sample payload to generate schema' - (this will generate Json schema for You)

    Parse Json component

  2. Enter Expression to parse XML to Json (use Content field in Parse Json Component -> Expression -> json(xml(triggerBody()))

    Parse JSON Expression

  3. Now You can use Your structure as dynamic objects in Logic App designer:

    Available dynamic content

Upvotes: 0

AdAstra
AdAstra

Reputation: 1984

json(XML(Body('WhateverYouAreParsing'))). My point here is that you can always cast the XML to JSON and work with it as JSON. I guess you could then recast it as XML with XML() if you really need to reply with XML but that would probably require some additional work. Or use a Transform XML with an integration account and a map.

An azure function could be used to do the parsing also.

Upvotes: 2

Related Questions