[WS] Validate an XML string against a schema
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: validateXmlAgainstSchema
Parameters
Validate an XML Object against an XML Schema:
Parameter | Parameter Type | Required | Description |
---|---|---|---|
xmlObject | String | Yes | Specify the XML object that needs to be validated. |
xmlSchema | String | Yes | 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 a Response against an XML Schema:
Parameter | Parameter Type | Required | Description |
---|---|---|---|
response | ResponseObject | Yes | Specify the response object that needs to be validated. |
xmlSchema | String | Yes | 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 does not 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);