加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从多个级别选择XML文件中的特定节点

发布时间:2020-12-16 23:34:53 所属栏目:百科 来源:网络整理
导读:我有一个类似于这个格式的xml文件: benchmarkgroup id1/id rule idH1234/id severityHigh/severity /rule titleHow to win/title/groupgroup id2/id rule id5317/id severitylow/severity /rule titleHow to not/title/groupgroup id3/id rule idH15678/id
我有一个类似于这个格式的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 docoument中的每个组中选择组/ id,组/规则/ id,组/规则/严重性和组/标题值.

我试过这个,但它只是让我在那里的一部分:

I have tried $xml.benchmark.group | %{$_} | select title,id

我感谢您的帮助!

解决方法

这对我有用:

$xml.benchmark.group |
select @{ L = 'GroupID';      E = { $_.id } },@{ L = 'GroupTitle';   E = { $_.title } },@{ L = 'RuleID';       E = { $_.rule.id } },@{ L = 'RuleSeverity'; E = { $_.rule.severity } }

得出以下结论:

GroupID GroupTitle  RuleID RuleSeverity
------- ----------  ------ ------------
1       How to win  H1234  High
2       How to not  5317   low
3       How to be   H15678 medium
4       How to lose H454   High

上面的语法类似于SQL的SELECT Foo AS Bar,选择一个值(哈希表中的表达式或E)并为显示目的提供别名(哈希表中的Label或L).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读