Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, <code>javax.xml.bind.Validator</code> has been deprecated in favour of <code>javax.xml.validation.Schema</code> (<a href="https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/Schema.html" rel="noreferrer">javadoc</a>). The idea is that you parse your schema via a <code>javax.xml.validation.SchemaFactory</code> (<a href="https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/SchemaFactory.html" rel="noreferrer">javadoc</a>), and inject that into the marshaller/unmarshaller.</p> <p>As for your question regarding validation without marshalling, the problem here is that JAXB actually delegates the validation to Xerces (or whichever SAX processor you're using), and Xerces validates your document as a stream of SAX events. So in order to validate, you need to perform <em>some</em> kind of marshalling.</p> <p>The lowest-impact implementation of this would be to use a "/dev/null" implementation of a SAX processor. Marshalling to a null OutputStream would still involve XML generation, which is wasteful. So I would suggest:</p> <pre><code>SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(locationOfMySchema); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setSchema(schema); marshaller.marshal(objectToMarshal, new DefaultHandler()); </code></pre> <p><code>DefaultHandler</code> will discard all the events, and the <code>marshal()</code> operation will throw a JAXBException if validation against the schema fails.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload