[WS] Validate an XML string against a schema (PoC)

Important

  • This Proof of Concept (PoC) is not ready for production use. We recommend using this PoC for evaluation purposes only.
  • Download Katalon Studio version 8.3.1.alpha.

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.

Parameters

Validate an XML Object with an XML Schema

Parameter Parameter Type Mandatory Description
xmlObject String Required Specify the XML object that needs to be validated.
xmlSchema String Required Specify the XML schema used to validate the XML object.
flowControl FailureHandling Optional Specify failure handling schema to determine whether the execution should be allowed to continue or stop.

Validate the Response with an XML Schema

Parameter Parameter Type Mandatory Description
response ResponseObject Required Specify the response object that needs to be validated.
xmlSchema String Required Specify the XML schema used to validate the response object.
flowControl FailureHandling Optional Specify failure handling schema to determine whether the execution should be allowed to continue or stop.

Returns

Parameter Type Description
boolean
  • true: the response passes the validation.
  • false: the response doesn't pass the validation.

Exception:

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.validateXmlSchema(res, "example/xml/person.xsd");
WS.validateXmlSchema(xml, "example/xml/person.xsd");
WS.validateXmlSchema(xmlFile, "http://localhost:8080/api/users/xsd", FailureHandling.STOP_ON_FAILURE);

Feedback