Search code examples
javascriptarraysxmlpostmanpostman-testcase

How can i traverse through the below xml response in postman to achieve all continents using loop?


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <m:ListOfContinentsByNameResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
            <m:ListOfContinentsByNameResult>
                <m:tContinent>
                    <m:sCode>AF</m:sCode>
                    <m:sName>Africa</m:sName>
                </m:tContinent>
                <m:tContinent>
                    <m:sCode>AN</m:sCode>
                    <m:sName>Antarctica</m:sName>
                </m:tContinent>
                <m:tContinent>
                    <m:sCode>AS</m:sCode>
                    <m:sName>Asia</m:sName>
                </m:tContinent>
                <m:tContinent>
                    <m:sCode>EU</m:sCode>
                    <m:sName>Europe</m:sName>
                </m:tContinent>
                <m:tContinent>
                    <m:sCode>OC</m:sCode>
                    <m:sName>Ocenania</m:sName>
                </m:tContinent>
                <m:tContinent>
                    <m:sCode>AM</m:sCode>
                    <m:sName>The Americas</m:sName>
                </m:tContinent>
            </m:ListOfContinentsByNameResult>
        </m:ListOfContinentsByNameResponse>
    </soap:Body>
</soap:Envelope>

Solution

  • var jsonObject = xml2Json(pm.response.text());
    
    jsonObject['soap:Envelope']['soap:Body']['m:ListOfContinentsByNameResponse']['m:ListOfContinentsByNameResult']['m:tContinent'].forEach((a)=>console.log(a['m:sName']))
    

    use xml2json to convert xml to json