Reputation: 43
I need to extract usernames from lines similar to this one. The usernames are variable, so I imagine this has to be attacked with regex. (I am clueless about how to pull this off).
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">USER1</RowTotal>
<RowTotal RowNumber="1">USER2</RowTotal>
<RowTotal RowNumber="2">USER3</RowTotal>
<RowTotal RowNumber="3">USER4</RowTotal>
<RowTotal RowNumber="4">USER 5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
Upvotes: 0
Views: 31
Reputation: 7163
See answers for PowerShell and XML like How to iterate through XML in Powershell?
And also look into things like the below code
$data = @'
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">USER1</RowTotal>
<RowTotal RowNumber="1">USER2</RowTotal>
<RowTotal RowNumber="2">USER3</RowTotal>
<RowTotal RowNumber="3">USER4</RowTotal>
<RowTotal RowNumber="4">USER 5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
'@
$xml = [xml]$data
foreach ($row in $xml.RowGroups.RowGroup.RowGroup.RowTotal)
{
$row.'#text'
}
Upvotes: 2