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?

有帮助吗?

解决方案

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top