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
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (29,326)