0

I am trying to loop through XML Linked Nodes Powershell, but I cannot seem to seperate them.

<?xml version="1.0" encoding="utf-8"?>
<Test>
    <Settings>
        <SomeSetting>
            <AAA>Some Value</AAA>
            <BBB>Some Value</BBB>
        </SomeSetting>
        <AnotherSetting>
            <CCC>Some Value</CCC>
            <DDD>Some Value</DDD>
        </AnotherSetting>
    </Settings>
</Test>

Now $XML.Test.Settings contains

SomeSetting AnotherSetting


SomeSetting AnotherSetting

I cannot loop through these elements individually. I want to loop through them where I get an array where the first item is SomeSetting and the second is AnotherSetting

I've tried leveraging GetEnumerator() and Looping through ($XML.Test.Settings).ChildNodes, but I keep ending up with a System.Xml.XmlLinkedNode object containing everything in one chunk.

me1299
  • 11
  • 3

1 Answers1

0

Found out you can use the hidden Get_Name() function on the ChildNode.

($Xml.DocumentElement.Settings).ChildNodes.Get_Name()

Not sure why ChildNodes() return grand child nodes otherwise.

me1299
  • 11
  • 3
  • Powershell has built in XML and Xpath optiopns to handle these scenarios. Kindly go through [Handling XMLs in PS](https://stackoverflow.com/questions/18509358/how-to-iterate-through-xml-in-powershell) – Ranadip Dutta Dec 09 '22 at 18:28