Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Power shell脚本SelectSingleNode不工作_C#_.net_Powershell - Fatal编程技术网

C# Power shell脚本SelectSingleNode不工作

C# Power shell脚本SelectSingleNode不工作,c#,.net,powershell,C#,.net,Powershell,SelectSingleNode始终返回null。请帮助元素是命名空间限定的,因此您需要在查询中指定命名空间: $xmlFile = "D:\ServiceConfiguration.cscfg" [xml]$doc = Get-Content $xmlFile $node = $doc.SelectSingleNode("/ServiceConfiguration/Role/ConfigurationSettings[@name='DiagnosticsConnecti

SelectSingleNode始终返回null。请帮助

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

   $xmlFile = "D:\ServiceConfiguration.cscfg"  
   [xml]$doc = Get-Content $xmlFile 
   $node = $doc.SelectSingleNode("/ServiceConfiguration/Role/ConfigurationSettings[@name='DiagnosticsConnectionString']") 
   $node.value = "New-Value" 
   $doc.Save($xmlFile)

XPath错误或cscfg文件中使用了名称空间。没有输入文件很难回答。。
$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)