Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: JSON root object has multiple properties.


Issue


While working on a POC about Debatching in Logic Apps using For Each,  I was encountered with a below error when testing it









"InvalidTemplate. Unable to process template language expressions for action 'For_each' at line '0' and column '0': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'inputs'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'."


Why it happened


As I had to debatch an xml message coming as payload in trigger, following xpath expression was provided to ForEach action i.e.

xpath(xml(trigger()),'//*[local-name()="PurchaseOrder" and namespace-uri()
="http://www.adventure-works.com"]')


And when xml message was posted, the logic app was not able to apply
xpath on the trigger output.

It happened because trigger() is an Azure Workflow built-in FUNCTION,
which refers the entire trigger object (including headers and body).

Thus at runtime, when expression tried to apply XML() function which
expects string it found JSON trigger Object.

So error was returned -

 The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document.


What to do


The xml payload which is passed along with trigger goes into trigger().outputs.body at runtime.

And triggerBody() is shorthand for it and it's type is String, so either of it has to be provided  to XML() function .


So the correct expression is


xpath(xml(triggerBody()),'//*[local-name()="PurchaseOrder" and namespace-uri()
="http://www.adventure-works.com"]')

In the above expression first triggerBody() (which is string) is casted in XML using xml() function and then xpath function is applied.


That's it, all worked fine.



If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!


Learn More about some more Logic App errors

  • The request has both SAS authentication scheme and 'Bearer' authorization scheme. Only one scheme should be used
  • Selected file must be between 1 and 2097152 bytes
  • SplitOn property doesn't validate expression at design time
  • The workflow with 'Response' action type should not have triggers with 'splitOn' property
  • The template language expression 'xxx' cannot be evaluated because property 'xxx' doesn't exist. Property selection is not supported on content of type 'application/xml'


This post first appeared on TechFindings, please read the originial post: here

Share the post

The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: JSON root object has multiple properties.

×

Subscribe to Techfindings

Get updates delivered right to your inbox!

Thank you for your subscription

×