【发布时间】:2020-11-21 12:28:18
【问题描述】:
我的 xml 与下面的普通 xml 略有不同,xmlns 不在根级别,它是从根开始的 2 级深度,我无法使用以下解决方案。谁能帮我选择节点。提前致谢。
我无法使用下面的 sn-p 来选择节点
$ns = New-Object System.Xml.XmlNamespaceManager($WebConfigXml.NameTable)
$ns.AddNamespace("ns", $WebConfigXml.DocumentElement.NamespaceURI)
$node = $WebConfigXml.SelectSingleNode("//ns:add[@key='SiteDomain']", $ns)
XML:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<app1>
</app1>
<assembly>
<runtime xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<location path="." inheritInChildApplications="false">
<appSettings>
<!--IT Ops-->
<add key="SomeOtherKey" value="SomeOtherValue" />
<add key="SiteDomain" value="somedomain.com" />
<add key="SomeOtherKey" value="SomeOtherValue" />
....
</appSettings>
</location>
</runtime>
</assembly>
</configuration>
【问题讨论】:
标签: powershell namespaces xml-namespaces selectsinglenode