'Azure Logic App - xpath for xml with namespace prefix

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



Solution 1:[1]

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/\"]')

Solution 2:[2]

I did what Johns-305 suggested.

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

Solution 3:[3]

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

Solution 4:[4]

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"]')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Van Eycken
Solution 2 Adeel bin Khalid
Solution 3 Paco de la Cruz
Solution 4 AdamKent