从 XML 中删除元素
我有以下格式的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将其视为删除不匹配的内容,而应将其视为复制匹配的内容。使用
元素 选择您想要保留的所有标签。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.