Java tutorial
//package com.java2s; import java.io.IOException; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.xml.sax.SAXException; public class Main { public static void validateSChema(String xmlFile, String... xsdFiles) throws SAXException, IOException { Source[] schemas = new Source[xsdFiles.length]; for (int i = 0; i < schemas.length; i++) { schemas[i] = new StreamSource(xsdFiles[i]); } SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); Schema schema = schemaFactory.newSchema(schemas); Validator validator = schema.newValidator(); Source source = new StreamSource(xmlFile); validator.validate(source); } }