I want to validate xml documents with JaXB.
Code :
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(new File("D:/liferay-develop/workspace/cat_test/v2/STD_MP.xsd")));
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
Now i want to get error if document not valide to schema. In examples is see that guys create EventHandler classes for this ( like this http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html). But maybe exist more simplest way to get validation error in conlose and in variable?
The
ValidationEventHandlerapproach is how you get a handle on the validation events. You could do something like the following if you are looking to minimize the amount of code you need to write: