mystack
mystack

Reputation: 5482

get immediate child node of a parant node of an xml file using powershell

I have an xml file like given below

 <ParentNode>
   <childnode1>
    <Name string="Code1"/>
   </childnode1>

   <childnode2>
    <Name string="Code2"/>
   </childnode2>
   <childnode3>
    <Name string="Code3"/>
   </childnode3>
</ParentNode>

how can i print all the child nodes of ParentNode using powershell

i tried by using given code

foreach($child in $xmlfile.ParentNode)
{
Write-Host $child
}

it should print

childnode1
childnode2
childnode3

Upvotes: 2

Views: 205

Answers (1)

Lo&#239;c MICHEL
Lo&#239;c MICHEL

Reputation: 26120

PS>[xml]$x=gc c:\temp\xml.xml    
PS>$x.ParentNode            

or maybe you want :

PS>$x.ParentNode |gm -MemberType property |select -expand name     
childnode1                                                         
childnode2                                                         
childnode3        

Upvotes: 1

Related Questions