-1

私は次のxmlを持っています:

<?xml version="1.0" encoding="utf-8"?>
<ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Reference Alias="MicrosoftSystemCenterNetworkDeviceLibrary6172210">
        <ID>Microsoft.SystemCenter.NetworkDevice.Library</ID>
        <Version>7.0.9538.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
<DisplayString ElementID="SC_e307a242ac6341079fb4e6446bd2ae05_Service_b7434c612faf4f488b33dc409a2cdd1a">
          <Name>name1</Name>
</DisplayString>
<DisplayString ElementID="SCIMembership_029d2e1209624b97af70462cb18aac4a_HealthMonitor">
       <Name>Component Group Health Roll-up for type Target Host</Name>
        <Description>The health of this Component is determined by the health of its members. This monitor rolls up health from each of the members of this Component.

    </Description>
    </DisplayString>
     <DisplayString ElementID="SC_7ece04875a51404db40b704244605b74_Service_b7434c612faf4f488b33dc409a2cdd1a">
              <Name>name2</Name>
    </DisplayString>
            <DisplayString ElementID="SCIMembership_04137e55024b4bc9a436668abc878d19_HealthMonitor">
              <Name>Component Group Health Roll-up for type Target Host</Name>
              <Description>The health of this Component is determined by the health of its members. This monitor rolls up health from each of the members of this Component.</Description>
            </DisplayString>
    <Reference Alias="MicrosoftSystemCenterNetworkDeviceLibrary6172210">
            <ID>Microsoft.SystemCenter.NetworkDevice.Library</ID>
            <Version>7.0.9538.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
          </Reference>
    </ManagementPack>

検索文字列を含むtxtファイルがあります:

SCIMembership_86a804b4c89148749da13e192240dc5f SCIMembership_f833b674da494d42b778637e89bbaca4

また、定義します$tagname = DisplayString

これらの検索文字列の xml を解析し、存在する場合は $tagname 全体を削除する必要があります。それは ElementID またはどこにでもある可能性があるため、タグ DisplayString 内にあり、検索文字列が見つかった場合は、それを削除する必要があります。

ループを試してみましたが、主な問題はアイテム/タグを検索する方法です。

4

1 に答える 1

0

これを試して:

$tagname = "DisplayString"
$xml= [xml] (Get-Content .\myxml.xml)#Read your xml
$serachString=[Io.File]::ReadAllText(".\mystr.txt")#Read search string text file
foreach ($node in $xml.ManagementPack.$tagname) {
    if ($serachString.Contains($node.ElementID)){$xml.ManagementPack.RemoveChild($node)}
}
$xml.Save(".\myxml.xml")
于 2013-08-17T07:20:26.353 に答える