如何在Postman中可视化XML SOAP信封

3
我将尝试使用提供的文档(这里)(这里)将我的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()
});

我尝试的是根据“结果 > 属性 > 属性 > 名称”动态生成所有标题列,并使值行从“结果 > 属性 > 属性 > 值”中传播。是否可能实现?

目前没有出错是因为负载是XML格式,而你正在将其解析为JSON格式。除非你在模板之前在脚本中进行转换。 - Danny Dainton
1个回答

2

这真的很糟糕,但它可以创建一个包含所需数据的表格,也许您可以在之后重构它:

// 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


我认为这几乎完成了,所有节点似乎都在“一行”而不是多个行中。 - InvalidSyntax
你需要调整handlebars代码,使其在需要的地方循环。我不知道完整的用例和您想要的最终结果,希望这能让您更接近目标。 - Danny Dainton

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接