2
命名空间中选择一个XML使用XPath属性我有一个内部节点NLOG一个.NET配置文件:与使用PowerShell
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target xsi:type="File" name="f" fileName="path to file" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="c,f" />
</rules>
</nlog>
</configuration>
我试图改变使用PowerShell中的target
的fileName
值。
我使用这个代码:
[xml]$xml = Get-Content $file
$ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$ns.AddNamespace("ns", $namespace) # $namespace is `http://www.nlog-project.org/schemas/NLog.xsd`
$values = $xml.selectNodes($xpath, $ns)
我的XPath表达式是//ns:nlog/ns:targets/ns:target[@ns:name='f']/@ns:fileName
但是$值总是0的结果。
有什么想法?我究竟做错了什么 ?
谢谢!