cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tibor4
Frequent Visitor

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
efialttes
Super User
Super User

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
Frequent Visitor

I have edited my post.

 

Thanks in advance.

efialttes
Super User
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,091)