Java, Software Development

Validate XML against an XSD that imports other XSDs

java Sort Enum Properties Monitor Directory File Lambda Expression parameter return types Validate XML String XSD ExecutorService AutoCloseable Try-With-Resources

This post demonstrates how to validate XML against XSD that imports other XSDs. This is different from validating against multiple independent XSDs.

Sample XSD Files

For our purpose, we have 4 XSD files.

Java codes

As usual, we need a Schema object to validate an XML file. The following codes create that object from using the main XSD file – Main.xsd. Given how our XSDs are authored, there is no need to specify the other XSD files in the codes.

The following set of codes use the Schema object to validate against an XML file.

Sample output:

Download the codes

You Might Also Like