如何使用PowerShell将SOAP响应对象转换为XML?
我将数据从我们的Web应用程序发送到Oracle UCM。我面临转换存储在文件中的肥皂响应的挑战。稍后,我从文件中读取该响应,然后转换为XML以获取响应代码。以下是代码:
$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
我在此行中遇到错误,
**[xml] $xml=$soap_object[5..6]**
无法从对象转换为XML文档。我花了很多时间来解决这个问题。但这是徒劳的。如果您知道答案,请回答我。
以下是我的肥皂反应。
--=_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--
提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
[XML] $ xml = $ soap_object [5..6]
to[XML] $ xml = $ soap_object [5]
,因为第六行(index5
)仅包含要解析的XML文本。但是,除非您需要文件中的标头字段,请考虑使用
$ response.content |外文件$ out_path
为了仅保存响应的 content ,即xml,然后允许您简化[xml] $ xml = $ xml = $ soap_object
Change
[xml] $xml=$soap_object[5..6]
to[xml] $xml=$soap_object[5]
, because the 6th line (index5
) 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