Xpath iteration using LogicApps

Lubdha Dolas 121 Reputation points
2023-02-22T11:32:02.1866667+00:00

I have a small data where the field is repeating. I want to iterate inside for every value.

<?xml version="1.0" encoding="UTF-8"?>
<RESULT error="0">
	<ROWSET>
		<ROW>
			<ACCESSKEYID>1234</ACCESSKEYID>
			<HSID/>
			<CARDCLASSID>2</CARDCLASSID>
			<RCN>002297</RCN>
			<PINCODE/>
      </Row>

		<ROW>
			<ACCESSKEYID>9862</ACCESSKEYID>
			<HSID/>
			<CARDCLASSID>4</CARDCLASSID>
			<RCN/>
			<PINCODE/>    
 </Row>

what i have tried is: json(json(string(xpath(xml(body('Accesskey')),'//ROW["ACCESSKEYIDM"]/ACCESSKEYID')))[0])?['ACCESSKEYID']

cause i need to iterate with accesskeyid. but this gives me only 1234 but want to iterate.
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2023-02-23T11:18:02.3966667+00:00

    @Lubdha Dolas Thanks for reaching out. Please correct if my understanding is right. You have the input as below

    <?xml version="1.0" encoding="UTF-8"?>
    <RESULT error="0">
       <ROWSET>
          <ROW>
             <ACCESSKEYID>1234</ACCESSKEYID>
             <HSID />
             <CARDCLASSID>2</CARDCLASSID>
             <RCN>002297</RCN>
             <PINCODE />
          </ROW>
          <ROW>
             <ACCESSKEYID>9862</ACCESSKEYID>
             <HSID />
             <CARDCLASSID>4</CARDCLASSID>
             <RCN />
             <PINCODE />
          </ROW>
       </ROWSET>
    </RESULT>
    
    

    You need the output for all the ACCESSKEYID as the array value.

    Output:

    ['1234','9862']

    Please confirm if my understanding is correct then you can leverage the below expression. Compose is my action where I am passing the XML content.

    xpath(xml(outputs('Compose')), '//ACCESSKEYID/text()')
    
    

    Workflow:

    User's image

    Output:

    User's image

    You can refer to xpath example in this document. Feel free to get back to me if you need any assistance.

    Please accept as "Yes" if the answer is helpful so that it can help others in the community. If you need any help/clarification/concerns/follow up questions, then please click on "Add Comment" on my answer and provide more details.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.