【发布时间】:2013-07-09 03:13:30
【问题描述】:
我正在尝试使用 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>
提前致谢!
【问题讨论】:
-
是错字吗?您的 xpath 有“人”,因为您没有具有该名称的 XML 节点......它应该是“人”吗?
-
请注明“似乎不起作用”。究竟发生了什么?我想我知道你预期会发生什么,但也可以指定这一点。
标签: xml powershell xpath scripting