gpt4 book ai didi

xml - 如何使用 Postman 可视化 XML SOAP 信封

转载 作者:行者123 更新时间:2023-12-01 07:05:18 24 4
gpt4 key购买 nike

我正在尝试使用提供的文档在 Postman 中将我的 SOAP 信封可视化为一个简单的表格 herehere .

这是我的有效载荷的样子:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>urn:uuid:e0817ed7-6575-4b05-8af4-0aa66bc3a428</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:49866f4c-0c5f-4d8e-b11d-cc194878215b</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-a0a30316-f6c4-4a36-bb48-13af93f451c6">
<wsu:Created>2020-03-11T17:14:16Z</wsu:Created>
<wsu:Expires>2020-03-11T17:19:16Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</env:Header>
<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<OverallStatus>OK</OverallStatus>
<RequestID>83222ed5-75a0-4ac0-8bb3-e3f76fdf89f9</RequestID>
<Results xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true"/>
<ObjectID xsi:nil="true"/>
<Type>DataExtensionObject</Type>
<Properties>
<Property>
<Name>key</Name>
<Value>11223344</Value>
</Property>
<Property>
<Name>status</Name>
<Value>pending</Value>
</Property>
</Properties>
</Results>
<Results xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true"/>
<ObjectID xsi:nil="true"/>
<Type>DataExtensionObject</Type>
<Properties>
<Property>
<Name>subscriberkey</Name>
<Value>334455</Value>
</Property>
<Property>
<Name>status</Name>
<Value>sync_failure</Value>
</Property>
</Properties>
</Results>
</RetrieveResponseMsg>
</soap:Body>
</soap:Envelope>

到目前为止,这是我的测试脚本中的内容:

var template = `
<table bgcolor="#FFFFFF">
<tr>
{{#each}}
<td>{{header name}}</td>
{{/each}}
</tr>

{{#each}}
<tr>
<td>{{value}}</td>
</tr>
{{/each}}
</table>
`;

// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json()
});

我想做的是从 Results > Properties > Property > Name 动态生成所有标题列,并让值行从 Results > Properties > Property > Value

这可能吗?

最佳答案

这非常可怕,但它会创建一个包含您需要的数据的表,也许您可​​以在之后重构它:

// Convert the XML to JSON
let jsonData = xml2Json(pm.response.text());
// A nasty looking reference to the Results array
let resultsArray = jsonData["soap:Envelope"]["soap:Body"].RetrieveResponseMsg.Results

// Handlebars syntax for displaying the keys/values you want
var template = `
<table style="background-color:white";>
<tr style="background-color:#d1d1e7;">
{{#each response}}
{{#with Properties}}
{{#each Property}}
<td>{{Name}}</td>
{{/each}}
{{/with}}
{{/each}}
</tr>
<tr>
{{#each response}}
{{#with Properties}}
{{#each Property}}
<td>{{Value}}</td>
{{/each}}
{{/with}}
{{/each}}
</tr>
</table>
`;

pm.visualizer.set(template, {
response: resultsArray
});

enter image description here

关于xml - 如何使用 Postman 可视化 XML SOAP 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60641642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com