0
以下函數「有效」,因爲不會引發異常並將xml文檔保存到磁盤。然而,沒有我刪除節點實際上從文件中刪除:XmlNode.RemoveChild在Powershell中沒有效果
function RemoveInvalidFileNodes($file, $substring){
[xml]$xml = Get-Content $file
$nodes=$xml.SelectNodes("//File")
$substring = [regex]::Escape($substring)
foreach ($node in $nodes) {
if ($node.Name -match $substring)
{
$node.ParentNode.RemoveChild($node)
}
}
Write-Host $xml.OuterXml
$xml.Save
}
我一直在敲打我的頭在這幾個小時。請幫忙!
該死的我覺得很蠢。 :( –