【发布时间】:2020-12-30 15:19:55
【问题描述】:
我不想得到这个xml的所有id(xml不能改变)
<?xml version="1.0" encoding="ISO-8859-1"?>
<List>
<Person1>
<Id>E00023</Id>
<empName>Aadharsh</empName>
</Person1>
<Person2>
<Id>E00042</Id>
<empName>Raksha</empName>
</Person2>
</List>
我尝试了以下代码,但我不工作:( 问题是 Person1 和 Person2 是不同的名称。 我必须更改什么才能获得所有 ID?
$XMLfile = 'C:\test.xml'
[XML]$empDetails = Get-Content $XMLfile
foreach($module in $empDetails.List.$module){
Write-Host "Id :" $module.Id
}
使用这段代码,我只能得到 Person1 的 ID:
$XMLfile = 'C:\test.xml'
[XML]$empDetails = Get-Content $XMLfile
foreach($module in $empDetails.List.Person1){
Write-Host "Id :" $module.Id
}
【问题讨论】:
标签: xml powershell parsing