Code example for StreamSource

0
    	validateXML(xml,this.getClass().getClassLoader().getResourceAsStream("schema/sparql/sparql_result.xsd"));
    } 
     
    private void validateXML(String xml,java.io.InputStream schemaIn) throws Exception {
    	SchemaFactory sf=SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    	Schema schema=sf.newSchema(new StreamSource(schemaIn));
    	Validator validator=schema.newValidator();
    	StringBuilder errorBuilder=new StringBuilder();
    	try{ 
    		validator.validate(new StreamSource(new StringReader(xml)));
    	}catch (Exception e) {
    		e.printStackTrace();
    		fail("Error during validation of XML:\n" + e.getLocalizedMessage());
		} 
    } 
 
 
    /** 
     * Explicit RELS-EXT relation to collection object 
     * @throws Exception 
     */