[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
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 against 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 |
|
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);