$xmlFile = "D:\ServiceConfiguration.cscfg"
[xml]$doc = Get-Content $xmlFile
$node = $doc.SelectSingleNode("/ServiceConfiguration/Role/ConfigurationSettings[@name='DiagnosticsConnectionString']")
$node.value = "New-Value"
$doc.Save($xmlFile)
SelectSingleNode is always returning null. Please help
The elements are namespace qualified so you need to specify the namespace in your query:
$xmlFile = "D:\ServiceConfiguration.cscfg"
[xml]$doc = Get-Content $xmlFile
$ns = new-object Xml.XmlNamespaceManager $xml.NameTable
$ns.AddNamespace('dns', 'http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration')
$node = $doc.SelectSingleNode("/dns:ServiceConfiguration/dns:Role/dns:ConfigurationSettings[@name='DiagnosticsConnectionString']", $ns)
$node.value = "New-Value"
$doc.Save($xmlFile)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.