cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
moutinhoabreu
Advocate IV
Advocate IV

parse xml file from sharepoint library

Hi Community,

 

For every XML file saved in a specific sharepoint folder location,  i need to parse it with power automate and retrieve the date from XML Header. (Please check the xml example below, i need to pull EndDate fields.)

This is the sequence of my flow:

 

Screenshot 2021-03-02 at 00.17.31.png

 

 

I've tried to fetch data with Xpath but always returned a null result.

 

xpath(xml(outputs('XML')), 'EndDate')

 

 

 

 

 

Though it was something related with fetching on xml header, so i've made some tests to get info from the nodes, but also got a null result:

 

xpath(xml(outputs('XML')), '//ProductCode')

 

 

What can i be doing wrong?

 

The XML file example:

 

<ns:StockFile xmlns:ns="urn:StockFile:PT_1_02" xmlns:doc="urn:schemas-basda-org:schema-extensions:documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns:StockHeader>
<ns:FileVersion>1_02</ns:FileVersion>
<ns:TaxRegistrationNumber>00000000</ns:TaxRegistrationNumber>
<ns:FiscalYear>2020</ns:FiscalYear>
<ns:EndDate>2020-12-31</ns:EndDate>
<ns:NoStock>false</ns:NoStock>
</ns:StockHeader>
<ns:Stock>
<ns:ProductCategory>M</ns:ProductCategory>
<ns:ProductCode>341252452345</ns:ProductCode>
<ns:ProductDescription>Care Kit Tube</ns:ProductDescription>
<ns:ProductNumberCode>660042376824</ns:ProductNumberCode>
<ns:ClosingStockQuantity>188.0</ns:ClosingStockQuantity>
<ns:UnitOfMeasure>Un</ns:UnitOfMeasure>
<ns:ClosingStockValue>2133.48</ns:ClosingStockValue>
</ns:Stock>
<ns:Stock>
<ns:ProductCategory>M</ns:ProductCategory>
<ns:ProductCode>09003NAVFW16</ns:ProductCode>
<ns:ProductDescription>DEE NAVY</ns:ProductDescription>
<ns:ProductNumberCode>09003NAVFW16</ns:ProductNumberCode>
<ns:ClosingStockQuantity>1.0</ns:ClosingStockQuantity>
<ns:UnitOfMeasure>Un</ns:UnitOfMeasure>
<ns:ClosingStockValue>18.65</ns:ClosingStockValue>
</ns:Stock>

 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @moutinhoabreu,

 

You could use the following expression:

xpath(xml(outputs('Compose')),'string(/*[name()="ns:StockFile"]/*[name()="ns:StockHeader"]/*[name()="ns:EndDate"])')

Screenshot 2021-03-03 143141.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-litu-msft
Community Support
Community Support

Hi @moutinhoabreu,

 

You could use the following expression:

xpath(xml(outputs('Compose')),'string(/*[name()="ns:StockFile"]/*[name()="ns:StockHeader"]/*[name()="ns:EndDate"])')

Screenshot 2021-03-03 143141.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-litu-msft
Community Support
Community Support

Here is the document about xpath() function:

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#x... 

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for the reply!

I was aware of this document and I've tried using this expression:

xpath(xml(outputs('XML')), 'Stock/FiscalYear')

 

outputs('XML') is previous compose step where I've placed the content of the file from get file content.

 

I get an empty input and empty output

Thanks

 

 

 

 

 

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,994)