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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Powershell has built in XML and Xpath optiopns to handle these scenarios. Kindly go through Handling XMLs in PS

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.