xpath logic app help

ShaneG 21 Reputation points
2021-05-11T22:18:43.767+00:00

I am trying to run an xpath and set a variable that I have previously intialized and running into issues with no value being provided.

Here is the xml example that is being retured via a HTTP Post:

<?xml version="1.0" encoding="utf-8"?>
<buyer_addedit_response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://cakemarketing.com/api/1/">
<success>true</success>
<message>Buyer (29) Created Successfully</message>
<row_count>0</row_count>
<buyer_id>29</buyer_id>
</buyer_addedit_response>

Here is the xpath I have set in the variable:
xpath(xml(outputs('Compose')),'/buyer_addedit_response/buyer_id[last()]')

The goal is the store the value 29 from the xml abovew in the variable I have created, but instead I am only getting [ ].

Any help would be appreciated.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,996 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,016 Reputation points
    2021-05-12T05:26:10.017+00:00

    Hi @ShaneG

    Welcome to Microsoft Q&A! Thanks for posting the question.

    As your XML response has a namespace you can refer to Example 8 and Example 9 of the xpath document
    I have tested it using the string variable content at my end therefore the first parameter of xpath I am converting my string content to XML

    xpath(xml(variables('xmlContent')),'string(/[name()="buyer_addedit_response"]/[name()="buyer_id"])')

    95831-image.png

    In your case it would be if you are converting to string or you can use int.
    xpath(xml(outputs('Compose')),'string(/[name()="buyer_addedit_response"]/[name()="buyer_id"])')

    Hope the above helps you to resolve the issue. Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful