Skip to main content

[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:
ParameterParameter TypeRequiredDescription
xmlObjectStringYesSpecify the XML object that needs to be validated.
xmlSchemaStringYesSpecify 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 a Response against an XML Schema:
ParameterParameter TypeRequiredDescription
responseResponseObjectYesSpecify the response object that needs to be validated.
xmlSchemaStringYesSpecify 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: If the response passes the validation.
  • false: If the response does not pass the validation.
notes

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);
Was this page helpful?