Code example for StreamSource

Methods: getSystemId

0
	 
	public static void main(String[] args) throws Exception {
		Source schemaFile = new StreamSource(
				new File(
				"src/main/resources/validation.xsd")); 
		Source xmlFile = new StreamSource(new File(
				"src/main/resources/data.xml")); 
 
		SchemaFactory schemaFactory = SchemaFactory
				.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		Schema schema = schemaFactory.newSchema(schemaFile);
		Validator validator = schema.newValidator();
 
		try { 
			validator.validate(xmlFile);
			System.out.println(xmlFile.getSystemId() + " is valid");
		} catch (SAXException e) {
			System.out.println(xmlFile.getSystemId() + " is NOT valid");
			System.out.println("Reason: " + e.getLocalizedMessage());
		} 
	} 
}