Skip to main content

[WS] Validate an XML string against a schema

Requirements

  • Katalon Studio version 8.4.0 onwards.

Description

Validate an XML response body, request body, or string against an XML schema. The XML schema input can be an XML string, URL, or file path.

Keyword name: WS.validateXmlAgainstSchema

Parameters

Validate an XML Object against an XML Schema

ParameterParameter TypeMandatoryDescription
xmlObjectStringRequiredSpecify the XML object that needs to be validated.
xmlSchemaStringRequiredSpecify the XML schema used to validate the XML object.
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.

Validate the Response against an XML Schema

ParameterParameter TypeMandatoryDescription
responseResponseObjectRequiredSpecify the response object that needs to be validated.
xmlSchemaStringRequiredSpecify the XML schema used to validate the response object.
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.

Returns

Parameter TypeDescription
boolean
  • true: the response passes the validation.
  • false: the response doesn't pass the validation.
Note:
  • If Katalon Studio cannot find the schema file or the response doesn't pass the validation, throw: StepFailedException.

Example

res = WS.sendRequest(findTestObject('XML'))

String xml = '''<?xml version="1.0" encoding="utf-8"?>
<List>
<item>
<id>3</id>
<username>James Johnson</username>
<password>789</password>
<gender>FEMALE</gender>
<age>75</age>
<avatar/>
</item>
</List>'''

String xmlFile = FileUtils.readFileToString(new File("example/xml/person.xml"));

WS.validateXmlAgainstSchema(res, "example/xml/person.xsd");
WS.validateXmlAgainstSchema(xml, "example/xml/person.xsd");
WS.validateXmlAgainstSchema(xmlFile, "http://localhost:8080/api/users/xsd", FailureHandling.STOP_ON_FAILURE);