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

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

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
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,631)