Code example for DOMSource

        // Parsers from this factory will automatically validate against the 
        // associated schema 
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(new InputSource(xml));
        schema.newValidator().validate(new DOMSource(doc));
     * Validate xml with xsd by sax. 
     * @param xsd the reader of xsd file. 
     * @param xml the reader of xml file. 
     * @throws Exception 
    public void validateWithSax(Reader xsd, Reader xml) throws Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser parser = null;
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Connect your IDE to all the code out there  Get Codota for Java