gpt4 book ai didi

c# - Powershell 脚本 SelectSingleNode 不工作

转载 作者:太空宇宙 更新时间:2023-11-03 19:29:58 25 4
gpt4 key购买 nike

   $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 总是返回 null。请帮忙

最佳答案

元素是命名空间限定的,因此您需要在查询中指定命名空间:

$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)

关于c# - Powershell 脚本 SelectSingleNode 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5634584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com