I have the following XML file. In this I want to filter all the city names that have employees with age 23.
Kindly help me with a PowerShell script.
I am expecting the answer "Chennai, Banglore".
<?xml version="1.0" ?>
<customers>
<city name="Chennai">
<Name>Anand</Name>
<Id>123</Id>
<Age>23</Age>
</city>
<city name="Banglore">
<Name>Arun</Name>
<Id>321</Id>
<Age>23</Age>
</city>
<city name="Mumbai">
<Name>Ashok</Name>
<Id>1</Id>
<Age>22</Age>
</city>
I have the following code to get the list of city names,
[xml]$test = Get-Content D:\test.xml
$names = $test.SelectNodes("/customers/city")
$sno = 0
foreach($node in $names)
{
$sno++
$id = $node.getAttribute("name")
Write-Host $sno $id
}
But how do I to filter the data?
Chenai, Bangloreas one value without unless you combine the two values yourself.