How to validate an XML against schema using JAXB?

后端 未结 1 1803
情深已故
情深已故 2020-12-30 04:58

I am working with XML and JAXB as I am unmarshalling and marshalling the XML into Java objects and vice versa. Now I am trying to validate our XML

相关标签:
1条回答
  • 2020-12-30 05:04

    You just need to set an instance of javax.xml.validation.Schema on the Unmarshaller before you do the unmarshal. You can specify an implementation of ValidationEventHandler on the Unmarshaller to catch any problems that occur during the unmarshal process.

    • http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/Unmarshaller.html#setSchema%28javax.xml.validation.Schema%29

    For More Information

    I have written more about this use case on my blog:

    • http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html
    0 讨论(0)
提交回复
热议问题