【发布时间】:2017-08-30 15:01:46
【问题描述】:
在 PowerShell 中,我尝试使用 XPath 检索属性的值。在下面的示例中,我想获取“hi”类别的“name”值,即“new test”。
示例代码展示:
<Report name="test" category="thisone">
<String>test</String>
<String>test2</String>
<Report name="new test" category="hi">
<String>hello</String>
<String>hi again</String>
</Report>
</Report>
这就是我所拥有的:
Select-Xml -XPath "//Report[@name='test']/Report" | Select name |
Out-File "result.txt"
我的结果是:
姓名 ----我真的不需要指定类别属性,因为<Report> 标记总是紧跟在第一个<Report> 标记之后,所以这就是为什么我认为使用 XPath 会更容易。
【问题讨论】:
标签: xml powershell xpath