Here you can find the source of getValidator(String path)
private static Validator getValidator(String path) throws SAXException, IOException
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.XMLConstants; 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 { private static Validator getValidator(String path) throws SAXException, IOException { String xsdUri = XMLConstants.W3C_XML_SCHEMA_NS_URI; SchemaFactory sf = SchemaFactory.newInstance(xsdUri); InputStream stream = new FileInputStream(path); StreamSource xsd = new StreamSource(stream); Schema schema = sf.newSchema(xsd); return schema.newValidator(); }/*from w w w . j a v a 2 s . co m*/ }