从 XML 中删除元素

发布于 2024-10-06 20:44:05 字数 3326 浏览 3 评论 0原文

我有以下格式的 XML:

<policy_groups>
    <policy_group>
    <policygroup_name>Application Server with IIS</policygroup_name>
        <policygroup_id>38</policygroup_id>
        <policygroup_description />
        <policygroup_creatorname>VMW2K3-SSI10-KF\VMW2K3-SSI10-KF\Administrator</policygroup_creatorname>
        <policygroup_patchgroup>-1</policygroup_patchgroup>
        <policygroup_signaturegroup>-1</policygroup_signaturegroup>
        <policygroup_system>false</policygroup_system>
        <policygroup_item>
            <policygroupitem_id>83217</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>Gold</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
        <policygroup_item>
            <policygroupitem_id>85541</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>SP1</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
    </policy_group>
    </policy_groups>

除了 XML 文档中有数千个

我需要删除 与以下任何组合不匹配的任何 policygroup_item

  • Windows 2000 Advanced服务器 SP4
  • Windows 2003 企业版 SP2
  • Windows 2003 企业版 (x64) SP2
  • Windows 2003 R2 企业版 SP2
  • Windows 2003 R2 企业版 (x64) SP2
  • Windows 2008 企业版 SP2
  • Windows 2008 企业版 (x64) SP2
  • Windows 2008 标准版 SP2
  • Windows 2008 R2 Standard (x64) Gold
  • Windows 2008 R2 Enterprise (x64) Gold

有没有办法使用 XSLT 或 powershell 来执行此操作?或者可能是 VB 脚本?

谢谢

布拉德

I have XML in the following format:

<policy_groups>
    <policy_group>
    <policygroup_name>Application Server with IIS</policygroup_name>
        <policygroup_id>38</policygroup_id>
        <policygroup_description />
        <policygroup_creatorname>VMW2K3-SSI10-KF\VMW2K3-SSI10-KF\Administrator</policygroup_creatorname>
        <policygroup_patchgroup>-1</policygroup_patchgroup>
        <policygroup_signaturegroup>-1</policygroup_signaturegroup>
        <policygroup_system>false</policygroup_system>
        <policygroup_item>
            <policygroupitem_id>83217</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>Gold</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
        <policygroup_item>
            <policygroupitem_id>85541</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>SP1</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
    </policy_group>
    </policy_groups>

Except there are thousands of <policygroup_item>'s in the XML document.

I need to remove any policygroup_item where <policygroupitem_productname> and <policygroupitem_spname> don't match any of the following combinations:

  • Windows 2000 Advanced Server SP4
  • Windows 2003 Enterprise Edition SP2
  • Windows 2003 Enterprise Edition (x64) SP2
  • Windows 2003 R2 Enterprise Edition SP2
  • Windows 2003 R2 Enterprise Edition (x64) SP2
  • Windows 2008 Enterprise Edition SP2
  • Windows 2008 Enterprise Edition (x64) SP2
  • Windows 2008 Standard Edition SP2
  • Windows 2008 R2 Standard (x64) Gold
  • Windows 2008 R2 Enterprise (x64) Gold

Is there some way to do this with XSLT or powershell? Or maybe VB script?

Thanks

Brad

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒解孤独 2024-10-13 20:44:05

不要将其视为删除不匹配的内容,而应将其视为复制匹配的内容。使用 元素 选择您想要保留的所有标签。

Don't think of it as removing the ones that don't match, think of it as copying the ones that do match. Use the <xsl:copy-of> element on a selection of all the tags you want to keep.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文