如何在Powershell中存在具有ID的父节点时删除子节点

时间:2014-08-05 06:38:31

标签: xml powershell

我有一个xml文件,我想从xml中删除现有子节点,其中有父节点具有特定ID使用Powershell

<

Portal PortalID="IPE">
      <DBConnection>
</DBConnection>
          <Spicer>
            <Filetype SpicerViewer="true">.jpg</Filetype>
            <Filetype SpicerViewer="true">.gif</Filetype>

           <Banner>
            <Top>
             <Left>fdgsf_FileName</Left>
             <Center>gsdfg_Revision</Center>
             <Right>Date</Right>
            </Top>
           <Bottom>
             <Left>dfgsdf_FileName</Left>
             <Center>fgsfd_Revision</Center>
             <Right>Date</Right>
           </Bottom>
         </Banner>
      </Spicer>
</Portal>

我必须完全根据Portal ID删除Banner节点,因为我的配置文件中有多个Portal Id

1 个答案:

答案 0 :(得分:0)

您可以使用:

[xml]$x=get-content c:\temp\data.xml

($x.portals.portal | ?{ $_.portalID -eq "IPE"}).spicer.banner.removeAll()

$x.save("c:\temp\newdata.xml")