Take the 2-minute tour ×

If XML is generated by JAXB classes(not by XSD), I don't have an XSD to validate. How do I validate the XML? Does the JAXB does validation of XML automatically before it starts unmarshalling?

share|improve this question
This existing question and answers might help : stackoverflow.com/questions/805989/… –  Patrice M. Jan 19 '13 at 1:13

1 Answer 1

up vote 1 down vote accepted

If you don't have XSD, JAXB will still perform "structual" validation. For example if you have annotated JAXB class property with "required" or specified specific "accessorder" and the input XML doesn't confirm to the annotation's values you will get exception. However you won't be able to perform "data" validation like specific XML element is restricted to have "8" character length (I believe JEE7 will integrate BeanValidation and wish JAXB leverages this spec).

share|improve this answer
Thank you for the response. Data Validation is what I am looking for. Do you have any recommendations? –  pingu Jan 19 '13 at 15:39
personally I still would prefer to have data validation in XSD. In your case it would be easy to generate XSD from JAXB using JDK schemagen tool and modify for data validation and follow the link @Patrice suggested. You must seriously explore Schematron as well. –  Baski Jan 20 '13 at 3:32

Your Answer


