Hi,
Suppose if I have an XSD and corresponding XML. And I need to validate this XSD against this XML.
I could able to do it using the below code,
SchemaFactory factory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaLocation = new File("samp.xsd");
Schema schema = factory.newSchema(schemaLocation);
Validator validator = schema.newValidator();
String file= "File.xml";
Source source = new StreamSource(file));
try {
validator.validate(source);
}
catch (SAXParseException ex) {
System.out.println(file +"is not valid because ");
System.out.println(ex.getMessage());
}
}
But if the xml is invalid, I want to get the exact message on which tag having the error. But using the above code I am not able to display that message.
I am getting the error as
cvc-datatype-valid.1.2.1: 'Ang' is not a valid value for 'integer'.
But I want to get the information like on which tag its showing error.
can anybody help me on this?
Regards,
Aneesh