强文字
我需要针对不同的Level对Itemno
进行分组例如: 1级:8000000377 - 1 8000000376 - 1 8000000378 - 2 8000000373 - 1 8000000371 - 1 2级:8000000373 - 2
<Root>
<Label>
<Dept>
<Line>
<Material>
<Level>1</Level>
<Type>abc</Type>
<Itemno>8000000377</Itemno>
</Material>
<Material>
<Level>1</Level>
<Type>abc</Type>
<Itemno>8000000376</Itemno>
</Material>
<Material>
<Level>1</Level>
<Type>123</Type>
<Itemno>8000000378</Itemno>
</Material>
<Material>
<Level>2</Level>
<Type>rth</Type>
<Itemno>8000000373</Itemno>
</Material>
</Line>
</Dept>
<Dept>
<Line>
<Material>
<Level>1</Level>
<Type>34r</Type>
<Itemno>8000000372</Itemno>
</Material>
<Material>
<Level>1</Level>
<Type>4th</Type>
<Itemno>8000000371</Itemno>
</Material>
<Material>
<Level>1</Level>
<Type>123</Type>
<Itemno>8000000378</Itemno>
</Material>
<Material>
<Level>2</Level>
<Type>dvg</Type>
<Itemno>8000000373</Itemno>
</Material>
</Line>
</Dept>
</Label>
</Root>
我尝试将密钥设置为:
但我的钥匙未绑定。
任何人都可以帮助我哪里出错了..
您可以使用 Xml Linq 来使用 powershell 脚本
using assembly System.Xml.Linq
$filename = 'c:\temp\test.xml'
$doc = [System.Xml.Linq.XDocument]::Load($filename)
$materials = $doc.Descendants('Material')
$table = [System.Collections.ArrayList]@()
foreach($material in $materials)
{
$newRow = [pscustomobject]@{
Level = $material.Element('Level').Value
Type = $material.Element('Type').Value
Itemno = $material.Element('Itemno').Value
}
$table.Add($newRow) | Out-Null
}
$groups = $table | Group-Object -Property Level
$groups | foreach { $_.Group | Format-Table}
结果
Level Type Itemno
----- ---- ------
1 abc 8000000377
1 abc 8000000376
1 123 8000000378
1 34r 8000000372
1 4th 8000000371
1 123 8000000378
Level Type Itemno
----- ---- ------
2 rth 8000000373
2 dvg 8000000373