Reputation: 16823
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
Reputation: 1
You cannot do that directly.
What I am doing is I am parsing it indirectly through XML - just as @AdAstra mentioned.
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"
}
]
}
}
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)
Enter Expression to parse XML to Json (use Content field in Parse Json Component -> Expression -> json(xml(triggerBody()))
Now You can use Your structure as dynamic objects in Logic App designer:
Upvotes: 0
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