0

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 ?

1 Answer 1

2

2 things wrong here:

  1. Namespace is not right
  2. Connection is not an attribute, so @ 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
Sign up to request clarification or add additional context in comments.

1 Comment

It works for me for XML from the question. If you have different XML - please post it

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.