---
schema_version: "1"
id: bd46ce1c11d9a0bff01bfdafbf9b469c227616bba69318ef132b150ef305b75c
title: Validate 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.3/xml-schema-validation.md
canonical_url: https://docs.mulesoft.com/xml-module/1.3/xml-schema-validation
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3d75bc7f0f9ea087b8fe874799ee34c4cb5e4631473b89589fd5e45741a76122
description: MuleSoft Documentation Site
release: "1.3"
latest: false
---
---
product: XML Module
version: 1.3
---

# Validate 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 XSD schema. The operation supports referencing many schemas, using a comma (`,`) as a
separator. By default, this operation looks for the input document at the message payload level, but
you can supply your own input as well. Note that you can use the **Validate schema** operation
inside the Validation module **All** scope.

## Configure the Validation Schema Operation in Studio

In the following example, you validate XML schemas that contain a script:

1.  In Studio, drag the **Validate schema** operation to your flow. In the **Schemas** field, add
    your schema files, separating filenames by using a comma, for example,
    `schema1.xsd, schema2.xsd`.

2.  Drag a **Flow Reference** component to the right of the **Validate schema** operation.

3.  Set **Flow name** to `processValidDocument`.

![In the Schemas field](/mulesoft/current/en-us/xml-module/1.3/_images/xml-validate-schema-1.png)

In the **Configuration XML** editor, the `<xml-module:validate-schema>` configuration looks like
this:

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

In the following example, you configure the **Validate schema** operation by supplying your own
input:

1.  In Studio, drag the File **Read** operation to your flow.

2.  In the configuration screen, set **File Path** to `document.xml`.

3.  In the **Advanced** tab, set **Target Variable** to `xmlDoc`.

4.  Drag the XML module **Validate schema** operation to the right of the **Read** operation.

5.  In the **Schemas** field, add your schemas and separate their names by using commas, for
    example, `schema1.xsd, schema2.xsd`.

6.  Set the **Content** field to the XML content to validate, for example, `#[vars.xmlDoc]`.

7.  Drag a **Flow Reference** component to the right of the **Validate schema** operation.

8.  Set **Flow name** to `processValidDocument`.

![In the Content field](/mulesoft/current/en-us/xml-module/1.3/_images/xml-validate-schema-2.png)

In the **Configuration XML** editor, the `<xml-module:validate-schema>` and `<xml-module:content>`
configurations look like this:

```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>
```

## Manage the Validation Error

If the validation is successful, the flow continues to the next operation. However, if the
validation fails, an `XML-MODULE:SCHEMA_NOT_HONOURED` error is raised.  
Because the validation can fail for more than one reason, the error description contains a list of
messages. Each message contains a `SchemaViolation` object that has the following structure:

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

In the following example, you configure the **Validate schema** operation and the
`XML-MODULE:SCHEMA_NOT_HONOURED` error in the Error Handler component:

1.  In Studio, drag the **Try** scope component to your flow.

2.  Drag the XML module **Validate schema** operation into the **Try** scope component.

3.  In the **Schemas** field, add your schema, for example, `schema.xsd`.

4.  In your flow, click the **Error handling** arrow to expand the error-handling section.

5.  Drag the **On Error Propagate** component into the **Error handling** section.

6.  Set the **Type** field to the Mule error handled by this on-error strategy, for example,
    `XML-MODULE:SCHEMA_NOT_HONOURED`.

7.  Deselect **Enable Notifications** and **Log Exception** fields.

8.  Drag a **For Each** scope component into the **On Error Propagate** component to iterate over
    each `errorMessage.payload`.

9.  Set the **Collection** field to the expression that splits the payload into individual pieces,
    for example, `#[error.errorMessage.payload]`.

10. Drag a **Logger** component into the **For Each** scope component to log the XML module error.

11. Set the **Message** field to the expression that contains the `SchemaViolation` objects that
    describe the message, for example,
    `#['At line: $(payload.lineNumber), column: $(payload.columnNumber) → $(payload.description)']`.

12. Save your changes.

13. Click the project name in **Package Explorer** and then click **Run > Run As > Mule
    Application**.

14. Navigate to the Console view to read the logger message:

    ```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.
    ```

    ![The XML module manage validation error flow](/mulesoft/current/en-us/xml-module/1.3/_images/xml-validate-schema-3.png)

In the **Configuration XML** editor, the
`<on-error-propagate type="XML-MODULE:SCHEMA_NOT_HONOURED">` configuration looks like this:

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

## See Also

- [XML Module Examples](https://docs.mulesoft.com/xml-module/1.3/xml-module-examples)

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