javascriptxmlpostmanaccess-token

How to parse in Postman body response from XML format


Using POST request in Postmat I received a body response as XML data like this.

    <?xml version='1.0' encoding='UTF-8'?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Body>
            <ns2:getAuthenticationTokenResponse xmlns:ns2="http://some_url.com" xmlns:ns3="http://some_url.com">
                <return>111222333</return>
            </ns2:getAuthenticationTokenResponse>
        </S:Body>
</S:Envelope>

And I need to get somehow value 111222333 as a collection variable. And I'm lost with solution since I have no experience with JS before. Please provide me with some solution.


Solution

  • maybe xml2js can resolve your question. this is sample code:

    const xml2js = require('xml2js');   
    xml2js.parseString(pm.response.text(), function (err, result) {
        console.log(result);
    });