Reputation: 21
I'm trying to get XML result but not in a string as I do:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://#####">
<SOAP-ENV:Body>
<ns0:ResumeOrderResponse xmlns:ns0="http://####" xmlns:ns1="http://######" ns1:transactionID="*********-">
<ns0:ResponseStatus ns1:code="1">
<ns1:message>Order not found</ns1:message>
</ns0:ResponseStatus>
</ns0:ResumeOrderResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is the way I am handling it:
$header = @{"Authorization" = '********';"SOAPAction"='ResumeOrder'}
$post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml -ContentType "application/soap+xml"
$bn = [xml]$post.Content
Write-Output $bn
I am trying to get just the line in the element "ns1:message", which is in this case "Order not found".
Upvotes: 1
Views: 2370
Reputation: 1454
You can extract the "ns1: message" value like,
$bn.Envelope.Body.ResumeOrderResponse.ResponseStatus.message
Hope it helps!
Here is a sample which I tested locally,
$xmlString = [xml]@'
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://#####">
<SOAP-ENV:Body>
<ns0:ResumeOrderResponse xmlns:ns0="http://####" xmlns:ns1="http://######" ns1:transactionID="*********-">
<ns0:ResponseStatus ns1:code="1">
<ns1:message>Order not found</ns1:message>
</ns0:ResponseStatus>
</ns0:ResumeOrderResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'@
$xmlString.Envelope.Body.ResumeOrderResponse.ResponseStatus.message
Upvotes: 2