How to validate XML Response with Predicates/namespace

Below is my XML Response:

<env:Envelope xmlns:env="http://schemas" xmlns:wsa="http://www.w3.org">
	<env:Body>
		<BOR xmlns:oraxsl="http://www.oracle.com" xmlns:oracle-xsl-mapper="http://www.oracle2.com" xmlns:inp1="http://www.oracle2.com.xsd2" xmlns="http://www.oracle2.com.xsd3">
			<inp1:C>
				<ns0:Id xmlns:ns0="http://www.oracle2.com.xsd4">SK</ns0:Id>
				<ns0:Address xmlns:ns0="http://www.oracle2.com.xsd4">
					<ns0:Number>4</ns0:Number>
				</ns0:Address>
			</inp1:C>
		</BOR>
	</env:Body>
</env:Envelope>

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

var jsonObject = xml2Json(responseBody);
console.log(jsonObject);
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="http://www.oracle2.com.xsd4. 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.

image

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

pm.test("Id = SK", () => {
    pm.expect(id).to.eql("SK");
});
2 Likes

That works. Thanks for the help.

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