Code example for StreamSource

Methods: getSystemId

0
			String xmlPayload = (String) src;			
//			URL schemaFile = new URL("http://localhost:8081/schemas/opcinforegister.xsd"); 
			Source schemaFile = new StreamSource("http://localhost:8081/schemas/opcinforegister.xsd");
//			Source schemaFile = new StreamSource(new File("C://schemas//opcinforequest.xsd")); 
//	        Source xmlFile = new StreamSource(new File("C://schemas//opcrequest.xml")); 
			Source xmlSource = new StreamSource(new StringReader(xmlPayload));
	        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
	        
 
	        try{ 
	        	Schema schema = schemaFactory.newSchema(schemaFile);
	  	        Validator validator = schema.newValidator();
	            validator.validate(xmlSource);
	            System.out.println("Document is valid");
	        } 
	        catch (SAXException e) 
	        {	        	 
	            System.out.println(xmlSource.getSystemId() + " is NOT valid");
	            System.out.println("Reason: " + e.getLocalizedMessage());
	            return e;
	           
	        } catch (IOException e) {				
				e.printStackTrace();
Stop searching for code, let great code find you!  Add Codota to your java IDE