0
的屬性我有刪除的XElement
<compilation defaultLanguage="c#" debug="true" targetframework="4.0">
</compilation>
我想刪除屬性調試和targetframework在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]
{
}
}
類型的XML節點
但我無法刪除節點。請幫助:)
:非常感謝你,它的工作:) – user1595214