cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Dual Super User III
Dual Super User III

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!



Highlighted
Frequent Visitor

Re: Xpath and arrays with apply to each

I have edited my post.

 

Thanks in advance.

Highlighted
Dual Super User III
Dual Super User III

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Users online (10,386)