我正在尝试使用 powershell 和 XPath 来选择下面 xml 示例中显示的名称属性。
$xml_peoples= $file.SelectNodes("//people")
foreach ($person in $xml_peoples){
echo $person.attributes
#echo $person.attributes.name
}
上面是我正在运行的代码,试图获取名称,但它似乎不起作用。有什么建议吗?
<peoples>
<person name='James'>
<device>
<id>james1</id>
<ip>192.192.192.192</ip>
</device>
</person>
</peoples>
提前致谢!
最佳答案
这两行就足够了:
[xml]$xml = Get-Content 'C:\path\to\your.xml'
$xml.selectNodes('//person') | select Name
关于xml - 在powershell中使用xpath选择xml中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17583373/