How to validate XML Response with Predicates/namespace

Below is my XML Response:

<env:Envelope xmlns:env="http://schemas" xmlns:wsa="">
		<BOR xmlns:oraxsl="" xmlns:oracle-xsl-mapper="" xmlns:inp1="" xmlns="">
				<ns0:Id xmlns:ns0="">SK</ns0:Id>
				<ns0:Address xmlns:ns0="">

I can pass if I want to validate ns0:Number element with below code.

var jsonObject = xml2Json(responseBody);
tests["Check Mode Id is 4 "+jsonObject['env:Envelope']['env:Body'].BOR['inp1:C']['ns0:Address']['ns0:Number']] = jsonObject['env:Envelope']['env:Envelope']['env:Body'].BOR['inp1:C']['ns0:Address']['ns0:Number']=== "4";

But if I want to validate ns0:Id it is providing [object Object] | AssertionError: expected false to be truthy
I guess this is due to ns0:Id element have xmlns:ns0=" So how to validate ns0:Id element value is my question. Code need fix is below.

tests["Check Id is SK "+jsonObject['env:Envelope']['env:Body'].BOR['inp1:C']['ns0:Id']] = jsonObject['env:Envelope']['env:Body'].BOR['inp1:C']['ns0:Id'] === "SK";

If you parse the elements one level at a time, you can see that the value for nso:Id is contained in the “_” key.


let id = jsonObject["env:Envelope"]["env:Body"]["BOR"]["inp1:C"]["ns0:Id"]["_"];

pm.test("Id = SK", () => {

That works. Thanks for the help.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.