[英]Selecet XML Nodes by similar names in Powershell
我有一個xml
文件,看起來像:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ImageConfig>
<Image Name="">
<Include-Software></Include-Software>
<RoboCopy></RoboCopy>
<Image-Path></Image-Path>
<Software0>xyz</Software0>
<Software1>abc</Software1>
<Software2>def</Software2>
<Software3>ghf</Software3>
<Software4>wew</Software4>
<Software5>hjf</Software5>
</Image>
</ImageConfig>
我想選擇帶有Name Software*
所有節點來刪除該值。
只需使用Get-Content cmdlet加載文件,然后將結果轉換為xml
。 然后使用Where-Object cmdlet過濾ImageConfig.Image
所有子項,其中名稱與Software\\d+
匹配,並刪除該值。 最后,使用Save
方法將xml寫回:
$xmlFilePath = 'your_path_here.xml'
[xml]$xml = Get-Content $xmlFilePath
$xml.ImageConfig.Image.ChildNodes | Where-Object Name -Match 'Software\d+' | ForEach-Object {
$_.'#text' = ''
}
$xml.Save($xmlFilePath)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.