1

In my logic app i am using xpath() function to get the value of . I have tried different xpaths but getting error

'The template language function 'xpath' parameters are invalid: the 'xpath' parameter must be a supported, well formed XPath expression. Please see https://aka.ms/logicexpressions#xpath for usage details.'.

i have the following xml:

enter image description here

I have tried:

@xpath(xml(<YourMessage>), '/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]')
@xpath(xml(<YourMessage>), 'string(/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"])')

but getting the same error enter image description here

6 Answers 6

2

You might be better off converting to JSON and working with the data in that format. At least you can get rid of all the silly namespace complexities that way.

LogicApps is JSON focused internally so doing so would be slightly more 'correct' anyway.

You can find samples at: JSONPath - XPath for JSON

And an evaluator: JSONPath Online Evaluator

Sign up to request clarification or add additional context in comments.

2 Comments

any chance you could post an example? I am relatively new to LogicApps
In a logic app, you can convert XML to JSON and then select from the resulting object, but that's only useful if you have a direct path to the value you need to extract. Logic Apps don't have a built-in JSONPath implementation (or jq or jsonata or ...). Also beware of converting XML to JSON where you're expecting an array (eg. purchase order lines). If there's only one record, it'll be a JSON object rather than an array with a single item.
2

You can include the namespace in your xpath using this expression:

@xpath(YOURBODY, '/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]')

1 Comment

I am getting the same error. Have a look at the screenshot
1

I did what Johns-305 suggested.

json(<Output>)['soap:Envelope']['soap:Body']

Comments

1

Coming to this late, but the error is because you've escaped the double-quotes in the designer (which automagically escapes double-quotes for you).

This is from the Reference guide to expression functions for Azure Logic Apps and Power Automate:

Important

If you work in code view, escape the double quotation mark (") by using the backslash character (\). For example, you need to use escape characters when you serialize an expression as a JSON string. However, if you're work in the Logic App Designer or expression editor, you don't need to escape the double quotation mark because the backslash character is added automatically to the underlying definition, for example:

Code view: xpath(xml(body('Http')), '/*[name()=\"file\"]/*[name()=\"location\"]')

Expression editor: xpath(xml(body('Http')), '/*[name()="file"]/*[name()="location"]')

Comments

0

If what you need is the value of one of the internal nodes, you can try:

@xpath(<YourMessage>, 'string(/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[name()=\"SearchByABNv201408Response\"]/*[name()=\"ABRPayloadSearchResults\"]/*[name()=\"Request\"]/*[name()=\"identifierSearchRequest\"]/*[name()=\"authenticationGUID\"])')

I hope this points you in the right direction

1 Comment

I am getting the same error. Have a look at the screenshot
0

You don't really need to scape the " characters, from the portal editor, you can simply put the xpath like this:

xpath(xml(body('Transform_XML')), '/*[local-name()="root" and namespace-uri()=""]/*[local-name()="X12_00401_210" and namespace-uri()="http://schemas.microsoft.com/BizTalk/EDI/X12/2006"]')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.