我有一个 Xml 类型的节点
<compilation defaultLanguage="c#" debug="true" targetframework="4.0">
</compilation>
我想在 powershell 中删除属性调试和目标框架
<compilation defaultLanguage="c#">
</compilation>
我正在使用以下代码这样做
function Remove-Attribute([xml]$document,[string]$propertyName)
{
try
{
$ns = New-Object Xml.XmlNamespaceManager $document.NameTable
$ns.AddNamespace("ns","WDA.Application.Configuration")
$configurationInfo = Get-ConfigurationInfo $propertyName
$node = $document.selectSingleNode($ConfigurationInfo.XPath,$ns)
If($node -eq $null)
{
throw "ERROR: The '" + $propertyName + "' setting was not found using XPath: " + $configurationInfo.XPath
}
else
{
$node.Attributes("debug").Remove()
$node.Attributes("targetframework").Remove()
$document.Save()
}
}
catch [Exception]
{
}
}
但我无法删除节点。请帮助:)