0
votes

I am having trouble working with xml messages within Azure logic apps. I read quite a few threads about similar issues but somehow it is not working for me :-)

My situation:

I post an xml message to service bus from a logic app. It seems like messages can only be send to a Topic when it is in Base64 encoding. So I use the following :

                    "ContentData": "@{base64(outputs('Compose_first_XML_message'))}",
                    "ContentType": "Application/xml"

Please note that the content has this format already:

"$content-type": "application/xml;charset=utf-8",
"$content": "PG5zMjpNZXRlb0RhdGEgeG1sbnM6bnMyPSJodHRwOi8vR2R...

After executing this action I see the message is delivered to Service Bus Topic. The Service Bus Explorer tool shows this MessageText:

[{"$content-type":"application/xml;charset=utf-8","$content":"PG5zMjpNZXRlb0RhdGEgeG1sbnM6bnMyPSJodHRwOi8vR2RmLkNvcmUuU2NoZW1hcy5NZXRlb0RhdGEudjEwMCI+DQogIDxJZD5aTV9USV9PVVRTSURFPC9JZD4NCiAgPFZhbHVlPjkuOTwvVmFsdWU+DQogIDxUaW1lU3RhbXA+MTQtTUFSLTIwMTggMTE6MTA6MDA8L1RpbWVTdGFtcD4NCiAgPG5zMTpNZXRhSW5mbyB4bWxuczpuczE9Imh0dHA6Ly9HZGYuQ29yZS5TY2hlbWFzLk1ldGFJbmZvLnYxMDIiPg0KICAgIDxTb3VyY2VTeXN0ZW0+R3NlcG4uZXh0LldlYldlYXRoZXJTdGF0aW9uPC9Tb3VyY2VTeXN0ZW0+DQogICAgPFNvdXJjZVN..."}]

Then I have another logic app which is triggered by messages on this Topic.I want to perform a Xml Transform action. The input code for this action is:

 "content": "@{xml(base64toString(triggerBody()?['ContentData']))}"

It results in this error:

InvalidTemplate. Unable to process template language expressions in action 'Transform_XML' inputs at line '1' and column '2610': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'Data at the root level is invalid. Line 1, position 1.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.

Thanks for reading ;-) What am I doing wrong here...?

2

2 Answers

0
votes

Do you use a Transform_XML shape? You don't need to convert to XML, you only have to pass the content:

"content": "@{base64toString(triggerBody()?['ContentData'])}"
0
votes

Ok, solved it:

"@xml(base64ToString(json(base64ToString(triggerBody()?['ContentData']))[0].$content))"