Home > Enterprise >  How to Convert SOAP Response Object to XML using PowerShell?
How to Convert SOAP Response Object to XML using PowerShell?

Time:05-14

I am sending data from our web application to Oracle UCM. I am facing challenges to convert SOAP response which is stored in a file. Later I am reading that response from the file and converting to XML to get the response code. Below is the code:

$response | Out-File  $out_path
$Status=($response.Envelope.Body.uploadFileToUcmResponse.return) 
Write-Host $Status
$soap_object= get-content -path $out_path
[xml] $xml=$soap_object[5..6]
$result=$xml.Envelope.Body.uploadFileToUcmResponse.result."#text"
$result 

I am getting error in this line

**[xml] $xml=$soap_object[5..6]**

Unable to convert from object to xml document. I have spend lot time to resolve this issue. but it was in vain. If you know the answer please respond me.

Below is my SOAP response.

--=_Part_920_1255941941.1652372974539
Content-Type: application/xop xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <83415eb1-1a64-4eeb-be91-e4ad0b837350>

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"><env:Header><wsa:Action>http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/FinancialUtilService/uploadFileToUcmResponse</wsa:Action><wsa:MessageID>urn:uuid:92433bfb-3f44-4a99-8513-8c2a274818fa</wsa:MessageID></env:Header><env:Body><ns0:uploadFileToUcmResponse xmlns:ns0="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/types/"><result xmlns="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/types/">10211536</result></ns0:uploadFileToUcmResponse></env:Body></env:Envelope>
------=_Part_920_1255941941.1652372974539--

Thanks in advance.

CodePudding user response:

Change [xml] $xml=$soap_object[5..6] to [xml] $xml=$soap_object[5], because the 6th line (index 5) alone contains the XML text you want to parse.

However, unless you need the header fields in your file, consider using
$response.Content | Out-File $out_path in order to only save the response's content, i.e. just the XML, which then allows you to simplify to [xml] $xml=$soap_object

  • Related