繁体   English   中英

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

[英]How to visualize XML SOAP envelope using Postman

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

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

<?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
});

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM