-1
<?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>
Liam
  • 27,717
  • 28
  • 128
  • 190
Daxesh
  • 3
  • 1
  • 2
    Have you tried any method? If so, describe errors you have encountered – Doan Van Thang Feb 22 '21 at 11:40
  • I don't have much knowledge about xml traverse. Here what I have tried var responseJson = xml2Json(responseBody); var JsonFields = responseJson['soap:Envelope']['soap:Body']['m:ListOfContinentsByNameResponse']['m:ListOfContinentsByNameResult']['m:tContinent']['m:sName']; //console.log(JsonFields); JsonFields.forEach( field => { if (field.sName == 'Asia'){ console.log("Field = " + field.sName); //pm.expect(field.text()).to.include("Asia"); pm.expect(field.text().to.include("Successfully passed")); } }); – Daxesh Feb 22 '21 at 11:43
  • and I got response................................................. There was an error in evaluating the test script: TypeError: Cannot read property 'forEach' of undefined – Daxesh Feb 22 '21 at 11:46

1 Answers1

1
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

PDHide
  • 18,113
  • 2
  • 31
  • 46