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?
Asked
Active
Viewed 900 times
1 Answers
2
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).

Baski
- 829
- 8
- 14
-
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
-
1personally 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 03:32