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

The template language function 'xpath' expects its first parameter to be an XML object

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




"InvalidTemplate. Unable to process template language expressions for action
'For_each' at line '1' and column '1658': 'The template language function
'xpath' expects its first parameter to be an XML object.
The provided value is of type 'String'.
Please see https://aka.ms/logicexpressions#xpath for usage details.'."


Why it happened


As I had to debatch an xml message, following xpath expression was provided to ForEach action

xpath(triggerBody(),'//*[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
triggerbody

It happened because triggerBody() is an Azure Workflow built-in FUNCTION, which is used to access
the output of trigger(shorthand for trigger().outputs.body) and it’s return type
is String.

What to do


Logic app is very well equipped to process XML message apart from JSON, however if any expressions(functions) are to be applied on it then it has to be explicitly handled by casting it to xml and then use xml based functions.

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.




Related Post 

  • Getting Started with Logic Apps - Enterprise Application Integration
  • Getting Started with Logic Apps - EDI X12 Fundamentals
  • Getting Started with Logic Apps - What happened to the Request?
  • Getting Started with Logic Apps - Fundamentals
  • Getting Started with Logic Apps - AS2
  • Getting Started with Logic Apps - XML to EDI X12
  • The provided map definition is not valid
  • Required property 'content' expects a value but got null. Path ''.'
  • Getting Started with Logic Apps - File Routing
  • Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
  • Inserting data in On Premises SQL Database using Logic Apps
  • Inserting Multiple Records In On Prem SQL Using Logic App
  • Check your request parameters to make sure the Path “” exists on your file system






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

    Share the post

    The template language function 'xpath' expects its first parameter to be an XML object

    ×

    Subscribe to Techfindings

    Get updates delivered right to your inbox!

    Thank you for your subscription

    ×