web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / XML iterate through no...
Power Automate
Answered

XML iterate through nodes and get values

(0) ShareShare
ReportReport
Posted on by 10

Hi!

 

I'm trying to loop over xml node and read each value in a structure like: (the actual structure is more complexe)

 

 

<main>
<records>
<year>2022</year>
</records>
<records>
<year>2021</year>
</records>
<records>
<year>2020</year>
</records>
</main>

 

 How can I perform this in a for each? in order to read each value.

I ve tried for each XpathQueryResult to get the <records> and after that CurrentItem.children[0].value - but is not possible. 

Please help!

I have the same question (0)
  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

     

    SET Text TO $'''<main>
    <records>
    <year>2022</year>
    </records>
    <records>
    <year>2021</year>
    </records>
    <records>
    <year>2020</year>
    </records>
    </main>'''
    File.GetTempPath TempFile=> TempFile
    File.WriteText File: TempFile TextToWrite: Text AppendNewLine: False IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.DefaultEncoding
    XML.ReadFromFile File: TempFile Encoding: XML.FileEncoding.DefaultEncoding XmlDocument=> XmlDocument
    XML.ExecuteXPathQuery.ExecuteXPath XmlDocument: XmlDocument XPathQuery: $'''main/records/year/text()''' XPathResults=> XPathResults
    LOOP FOREACH CurrentItem IN XPathResults
     Display.ShowMessageDialog.ShowMessage Message: CurrentItem Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True
    END

    Paste this code into PAD to see how.

     

  • john_doe Profile Picture
    10 on at

    Nice trick! it works perfectly.

    The node <Records> holds about 9 values: year, month, city ....

    I was hopping to extract with Xpath the Record node, and call each property on current Item like ... CurrentItem[Year].Value, CurrentItem[Month].Value or by index. 

    I Find Your solution limited to Year children. How it can be addapted to all values of <Record>?  

  • Verified answer
    Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at
    SET Text TO $'''<main>
    <records>
    <year>2022</year>
    </records>
    <records>
    <year>2021</year>
    </records>
    <records>
    <year>2020</year>
    </records>
    </main>'''
    File.GetTempPath TempFile=> TempFile
    File.WriteText File: TempFile TextToWrite: Text AppendNewLine: True IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.DefaultEncoding
    XML.ReadFromFile File: TempFile Encoding: XML.FileEncoding.DefaultEncoding XmlDocument=> XmlDocument
    XML.ExecuteXPathQuery.ExecuteXPath XmlDocument: XmlDocument XPathQuery: $'''main/records''' XPathResults=> XPathResults
    LOOP FOREACH CurrentItem IN XPathResults
     XML.ExecuteXPathQuery.ExecuteXPath XmlDocument: CurrentItem XPathQuery: $'''records/year/text()''' XPathResults=> Year
     Display.ShowMessageDialog.ShowMessage Message: Year Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True
    END

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 223

#2
David_MA Profile Picture

David_MA 210 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 175

Last 30 days Overall leaderboard