Reputation: 415
There are some code
123.xml:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<P2MessageServiceStatus>
<CONNECTION>CONNECTION_CONNECTED</CONNECTION>
<ROUTER>ROUTER_CONNECTED</ROUTER>
</P2MessageServiceStatus>
</SOAP:Body>
</SOAP:Envelope>
so, i am trying go get value using name Spaces. It runs ok without it, but with namespaces it does nothing
$url='http://123.xml'
$xpath='/SOAP:Envelope/SOAP:Body/P2MessageServiceStatus/@CONNECTION'
$namespace='SOAP'
$wc = New-Object Net.WebClient
[xml]$xml_body = $wc.DownloadString($url)
$xmlvalue= Select-Xml -XPath $xpath -Xml $xml_body -Namespace @{ SOAP = 'http://test'}
$xmlvalue will be empty with no errors, how to fix it ?
Upvotes: 0
Views: 137
Reputation: 13483
2 things wrong here:
@
is not necessary.This worked for me:
$xml = [xml] (gc e:\1.txt )
$xpath='/SOAP:Envelope/SOAP:Body/P2MessageServiceStatus/CONNECTION'
$xmlvalue= Select-Xml -XPath $xpath -Xml $xml -Namespace @{ "SOAP" = 'http://schemas.xmlsoap.org/soap/envelope/'}
$xmlvalue
Upvotes: 2