0

I have slightly diff xml from normal xml like below, xmlns is not at the root level, it is 2 level depth from the root, for which i'm unable to use below solution. Can anyone please help me select the node. Thanks in advance.

I'm unable to use below snippet to select the node

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

1 Answer 1

2

Your namespace is not initialized correctly in $ns. You need to drill down to the node that contains the namespace definition:

$ns.AddNamespace('ns',$WebConfigXml.configuration.assembly.runtime.NamespaceURI) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot AdminOfThings, This saved me a lot of time. I didn't find any examples for this:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.