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!
Solved! Go to Solution.
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
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.
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>?
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
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Announcing a new way to share your feedback with the Power Automate Team.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.