从多个级别选择 XML 文件中的特定节点
我有一个格式类似于以下内容的 xml 文件:
<benchmark>
<group>
<id>1</id>
<rule>
<id>H1234</id>
<severity>High</severity>
</rule>
<title>How to win</title>
</group>
<group>
<id>2</id>
<rule>
<id>5317</id>
<severity>low</severity>
</rule>
<title>How to not</title>
</group>
<group>
<id>3</id>
<rule>
<id>H15678</id>
<severity>medium</severity>
</rule>
<title>How to be</title>
</group>
<group>
<id>4</id>
<rule>
<id>H454</id>
<severity>High</severity>
</rule>
<title>How to lose</title>
</group></benchmark>
我希望能够从 xml 文档中的每个组中选择组/id、组/规则/id、组/规则/严重性和组/标题值。
我已经尝试过,但这只让我完成了部分任务:
I have tried $xml.benchmark.group | %{$_} | select title, id
感谢您的帮助!
I have an xml file in a format similar to this:
<benchmark>
<group>
<id>1</id>
<rule>
<id>H1234</id>
<severity>High</severity>
</rule>
<title>How to win</title>
</group>
<group>
<id>2</id>
<rule>
<id>5317</id>
<severity>low</severity>
</rule>
<title>How to not</title>
</group>
<group>
<id>3</id>
<rule>
<id>H15678</id>
<severity>medium</severity>
</rule>
<title>How to be</title>
</group>
<group>
<id>4</id>
<rule>
<id>H454</id>
<severity>High</severity>
</rule>
<title>How to lose</title>
</group></benchmark>
I would like to be able to select the group/id, group/rule/id, group/rule/severity and group/title values from each group in the xml docoument.
I have tried this but it only gets me part of the way there:
I have tried $xml.benchmark.group | %{$_} | select title, id
I appreciate your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用:
产生以下结果:
上面的语法类似于 SQL 的
SELECT Foo AS Bar
,选择一个值(Expression
或E
in哈希表)并提供用于显示目的的别名(哈希表中的Label
或L
)。This works for me:
yielding the following:
The syntax above is similar to SQL's
SELECT Foo AS Bar
, selecting a value (Expression
orE
in the hashtable) and providing an alias for display purposes (Label
orL
in the hashtable).这可以通过以下方式完成:
在命令行上。
希望对
JP有帮助
This can be done with :
On the command line.
I hope it helps
JP