简体   繁体   中英

JAXB 2.0 Validation Question

While working with JAXB 2.0 i came across a query which i am unable to solve so far,while doing the validation i have 2 options

1) Either as soon as i found the error throw the exception as i am done. 2) Move ahead if there is any error or validation and i assume this is the best way since it will help one to show all errors or warings with respect to the whole XML. but since this process also invlolves unmarshalling means it will unmarshall my provided XML is to respected Object even if there is any Error or warning.so all means extra work..

My question is is these a way so that i can do whole validation and if it is successfull only than should the corresponding XML be bind to respected POJO classes

thanks in advance

You can use the javax.xml.validation APIs to validate an XML document against an XML schema. The you can choose to unmarshal this object again using JAXB.

Below is an example of using these APIs. In this example the input is actually an object model, but you can adapt it to work with any XML input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM