I am trying to select nodes from an XML file but am encountering issue that appear to be caused by the namespace.
The code below does not return anything. But if I remove the namespace from the XML file, I obtain the expected out.
MWE
$StandaloneXML = "test.xml"
# Load XML content
$NewStandaloneXML = New-Object -TypeName "System.XML.XMLDocument"
$NewStandaloneXML.Load($StandaloneXML)
# Get namespace
$Namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $NewStandaloneXML.NameTable
$Namespace.AddNamespace("jboss", $NewStandaloneXML.DocumentElement.NamespaceURI)
$NewStandaloneXML.SelectNodes("jboss:server/interfaces/interface", $Namespace)
XML
<?xml version="1.0" ?>
<server xmlns="urn:jboss:domain:4.2">
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:127.0.0.1}"/>
</interface>
</interfaces>
</server>
Expected output
name inet-address ---- ------------ management inet-address public inet-address