---
schema_version: "1"
id: 6cdd26b606c15eb56fb48ea8670b25cc302733d4e31f3e142a787595ebcfc467
title: Validating Documents against an XSD Schema with the XML Module
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/xml-module/1.2/xml-schema-validation.md
canonical_url: https://docs.mulesoft.com/xml-module/1.2/xml-schema-validation
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 337c9ceb7768fcd65b6c7252efc518f7e9e60334bff51ff643f851adadb40806
description: MuleSoft Documentation Site
release: "1.2"
latest: false
---
---
product: XML Module
version: 1.2
---

# Validating Documents against an XSD Schema with the XML Module

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The `<xml-module:validate-schema>` operation validates that the input content is compliant with a
given schema. This operation supports referencing many schemas (using comma as a separator) that
include each other.

This example shows how to work with XML that contains the script of the play Othello by William
Shakespeare. The XML file looks something like this:

```xml
<flow name="process">
    <xml-module:validate-schema schemas="schema1.xsd, schema2.xsd" />
    <flow-ref name="processValidDocument" />
</flow>
```

By default, this operation looks for the input document at the message payload level. However, you
can supply your own input, for example:

```xml
<flow name="process">
    <file:read path="document.xml" target="xmlDoc" />
    <xml-module:validate-schema schemas="schema1.xsd, schema2.xsd">
        <xml-module:content>#[vars.xmlDoc]</xml-module:content>
    </xml:module:validate-schema>
    <flow-ref name="processValidDocument" />
</flow>
```

Note that you can use the `<xml-module:validate-schema>` component inside a `<validation:all>`
element.

## Handling the Validation Error

If the validation is successful, nothing happens, and the flow continues to the next operation. If
it fails, an `XML-MODULE:SCHEMA_NOT_HONOURED` error is raised.

The `XML-MODULE:SCHEMA_NOT_HONOURED` error is a complex one. Because the validation can fail for any
number of reasons, the error contains a list of Messages. Each message contains a `SchemaViolation`
object, which has the following structure:

SchemaViolation Object

```yaml
{ lineNumber: Number, columnNumber: Number, description: String }
```

Consider the following example:

```xml
 <flow name="extractErrorsFromException">
    <try>
        <xml-module:validate-schema schemas="schema.xsd" /> (1)
        <error-handler>
            <on-error-propagate type="XML-MODULE:SCHEMA_NOT_HONOURED"> (2)
                <foreach collection="#[error.errorMessage.payload]">
                    <logger level="ERROR" message="#['At line: $(payload.lineNumber), column: $(payload.columnNumber) -> $(payload.description)']" /> (3)
                </foreach>
            </on-error-propagate>
        </error-handler>
    </try>
</flow>
```

```none
ERROR 2018-02-16 14:35:45,722 [[MuleRuntime].cpuIntensive.01: [SchemaValidationTestCase#extractErrorsUsingExpressions].extractErrorsFromException.CPU_INTENSIVE @411e886b] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: At line: -1, column: -1 -> cvc-complex-type.2.4.a: Invalid content was found starting with element 'fail'. One of '{used}' is expected.
```

## See Also

[XML Module Overview](https://docs.mulesoft.com/xml-module/1.2/)
