Alex Gordon
Alex Gordon

Reputation: 60691

merging / coalescing xml records

Is it possible to do a coalesce against 2 records having the same schema?

Suppose I have 2 payloads such as:

<Person>
<Color></Color>
<First>Joe</First
<Last>Smith</Last>
<Date>1/1/2019</Date>
</Person>

And this one:

<Person>
<Color>Blue</Color>
<First></First
<Last>Smith</Last>
<Date></Date>
</Person>

Expected result:

<Person>
<Color>Blue</Color>
<First>Joe</First
<Last>Smith</Last>
<Date>1/1/2019</Date>
</Person>

How do we always take the non-empty value for a specific node?

Upvotes: 0

Views: 213

Answers (1)

Hury Shen
Hury Shen

Reputation: 15724

You can transform your xml to json and use "If" condition in logic app to coalesce the two xml file. Below is the whole screenshot of my logic app. enter image description here

Details:

First I upload the two xml files to azure storage blob and get them in logic app by "Get blob content" action. Then I initialize a variable named "jsonPersonString1" and use the expression to transform the blob content to json, then use "Parse JSON" action to parse it.(I post the screenshot below) enter image description here

Second please do same steps as above to transform the second xml file to json and parse it.(also post the screenshot below) enter image description here

Then I initialize variable named "result" and set its value as null. enter image description here

After that, create a "If" condition to judge which value we should use and set the outputs to the variable "result". Here I just do the operation for the property "Color", you can also do same operation for other properties. enter image description here

After complete the "If" condition, we can transform the json to xml. enter image description here

Hope it would be helpful to your problem~

Upvotes: 1

Related Questions