Reading XML file using Powershell

This post deals with reading XML file and then traversing through the nodes of XML and fetching node values using powershell commands.

consider the below xml fragment with file path location

<student ID="1" name="Sathya">
<student ID="2" name="Deepak">

#loading xml from mentioned path location into xml variable
[xml]$Xmlvar = Get-Content D:\myxml.xml 

#fetching values of xml nodes

$firststudent = $Xmlvar.STUDENTINFO.student[0]

$secondstudent = $Xmlvar.STUDENTINFO.student[1]
foreach( $student in $Xmlvar.STUDENTINFO.student)


Write-host $
Write-host $student.Id




No comments: