cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Tibor4
Level: Powered On

Xpath and arrays with apply to each

Hello!

 

I have an XML file which I want to parse to an e-mail message.

 

...

 

Action: Data Operation -> Compose: Produtcnames

 

 

 

xpath(xml(outputs('ValidXML')), '/invoice/items/item/productname')

 

 

 

 

Action: Control -> Apply for each: Apply for each product name

Selected output: outputs('Productnames')

      Action: Variable -> Increment variable: Increase product ID

                   Name: ProductID
                   Value: 1

 

      Action: Variable -> Append to array variable:  Add to productsArray

 

 

 

{
"No.:": @{variables('ProductID')},
"Product": @{replace(replace(decodeBase64(item()?['$content']),'<productname>',''),'</productname>','')}
}

 

 

 

 

The code above is working fine but I have an another step:

Action: Data Operation -> Compose: ProductPrices

 

 

 

xpath(xml(outputs('ValidXML')), '/invoice/items/item/productprice')

 

 

 

 

So I would like to modify

  Action: Variable -> Append to array variable:  Add to productsArray

 

 

 

{
"No.:": @{variables('ProductID')},
"Product": @{replace(replace(decodeBase64(item()?['$content']),'<productname>',''),'</productname>','')},
"Price": @{replace(replace(decodeBase64(item()?['$content']), '<productprice>', ''), '</productprice>', '')}
} 

 

 

 

 

 

But only the item() function can not be changed to

 

 

 

replace(replace(decodeBase64(outputs('ProductPrices')?['$content']), '<producprice>', ''), '</producprice>', '')

 

 

 

Here is the xml:

 

<?xml version="1.0" encoding="utf-8" ?>
<invoice>
	<items>
		<item id="5">
			<productname>Product one</productname>
			<productprice>1000</productprice>
		</item>
		<item id="7">
			<productname>Product two</productname>
			<productprice>9000</productprice>
		</item>
	</item>
</invoice>
​

 

3 REPLIES 3
Dual Super User
Dual Super User

Re: Xpath and arrays with apply to each

Hi
Can you share an example of your xml structure?
Thanx!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Tibor4
Level: Powered On

Re: Xpath and arrays with apply to each

I have edited my post.

 

Thanks in advance.

Dual Super User
Dual Super User

Re: Xpath and arrays with apply to each

Hi
Each xml item has a single Product Name, right?. Did you try to iterate through xml items instead of iterating through xml Product names?
Inside each iteration you should be able to grab current item's product name, product price, and append a new element to your array
Hope this helps


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Helpful resources

Announcements
firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,055)